Addshore has uploaded a new change for review.
https://gerrit.wikimedia.org/r/281267
Change subject: Move CookieJar class to own file
......................................................................
Move CookieJar class to own file
Change-Id: Ie98eadb2a8015f1290447b79cc095799abaeba4f
---
M autoload.php
M includes/libs/Cookie.php
A includes/libs/CookieJar.php
3 files changed, 104 insertions(+), 84 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/67/281267/1
diff --git a/autoload.php b/autoload.php
index fd4f873..f98bac3 100644
--- a/autoload.php
+++ b/autoload.php
@@ -269,7 +269,7 @@
'ConvertUserOptions' => __DIR__ . '/maintenance/convertUserOptions.php',
'ConverterRule' => __DIR__ . '/languages/ConverterRule.php',
'Cookie' => __DIR__ . '/includes/libs/Cookie.php',
- 'CookieJar' => __DIR__ . '/includes/libs/Cookie.php',
+ 'CookieJar' => __DIR__ . '/includes/libs/CookieJar.php',
'CopyFileBackend' => __DIR__ . '/maintenance/copyFileBackend.php',
'CopyFileOp' => __DIR__ . '/includes/filebackend/FileOp.php',
'CopyJobQueue' => __DIR__ . '/maintenance/copyJobQueue.php',
diff --git a/includes/libs/Cookie.php b/includes/libs/Cookie.php
index cc236e2..a67b919 100644
--- a/includes/libs/Cookie.php
+++ b/includes/libs/Cookie.php
@@ -206,86 +206,3 @@
return $this->isSessionKey || $this->expires > time();
}
}
-
-class CookieJar {
- private $cookie = [];
-
- /**
- * Set a cookie in the cookie jar. Make sure only one cookie per-name
exists.
- * @see Cookie::set()
- * @param string $name
- * @param string $value
- * @param array $attr
- */
- public function setCookie( $name, $value, $attr ) {
- /* cookies: case insensitive, so this should work.
- * We'll still send the cookies back in the same case we got
them, though.
- */
- $index = strtoupper( $name );
-
- if ( isset( $this->cookie[$index] ) ) {
- $this->cookie[$index]->set( $value, $attr );
- } else {
- $this->cookie[$index] = new Cookie( $name, $value,
$attr );
- }
- }
-
- /**
- * @see Cookie::serializeToHttpRequest
- * @param string $path
- * @param string $domain
- * @return string
- */
- public function serializeToHttpRequest( $path, $domain ) {
- $cookies = [];
-
- foreach ( $this->cookie as $c ) {
- $serialized = $c->serializeToHttpRequest( $path,
$domain );
-
- if ( $serialized ) {
- $cookies[] = $serialized;
- }
- }
-
- return implode( '; ', $cookies );
- }
-
- /**
- * Parse the content of an Set-Cookie HTTP Response header.
- *
- * @param string $cookie
- * @param string $domain Cookie's domain
- * @return null
- */
- public function parseCookieResponseHeader( $cookie, $domain ) {
- $len = strlen( 'Set-Cookie:' );
-
- if ( substr_compare( 'Set-Cookie:', $cookie, 0, $len, true )
=== 0 ) {
- $cookie = substr( $cookie, $len );
- }
-
- $bit = array_map( 'trim', explode( ';', $cookie ) );
-
- if ( count( $bit ) >= 1 ) {
- list( $name, $value ) = explode( '=', array_shift( $bit
), 2 );
- $attr = [];
-
- foreach ( $bit as $piece ) {
- $parts = explode( '=', $piece );
- if ( count( $parts ) > 1 ) {
- $attr[strtolower( $parts[0] )] =
$parts[1];
- } else {
- $attr[strtolower( $parts[0] )] = true;
- }
- }
-
- if ( !isset( $attr['domain'] ) ) {
- $attr['domain'] = $domain;
- } elseif ( !Cookie::validateCookieDomain(
$attr['domain'], $domain ) ) {
- return null;
- }
-
- $this->setCookie( $name, $value, $attr );
- }
- }
-}
diff --git a/includes/libs/CookieJar.php b/includes/libs/CookieJar.php
new file mode 100644
index 0000000..910a7ca
--- /dev/null
+++ b/includes/libs/CookieJar.php
@@ -0,0 +1,103 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup HTTP
+ */
+
+class CookieJar {
+ private $cookie = [];
+
+ /**
+ * Set a cookie in the cookie jar. Make sure only one cookie per-name
exists.
+ * @see Cookie::set()
+ * @param string $name
+ * @param string $value
+ * @param array $attr
+ */
+ public function setCookie( $name, $value, $attr ) {
+ /* cookies: case insensitive, so this should work.
+ * We'll still send the cookies back in the same case we got
them, though.
+ */
+ $index = strtoupper( $name );
+
+ if ( isset( $this->cookie[$index] ) ) {
+ $this->cookie[$index]->set( $value, $attr );
+ } else {
+ $this->cookie[$index] = new Cookie( $name, $value,
$attr );
+ }
+ }
+
+ /**
+ * @see Cookie::serializeToHttpRequest
+ * @param string $path
+ * @param string $domain
+ * @return string
+ */
+ public function serializeToHttpRequest( $path, $domain ) {
+ $cookies = [];
+
+ foreach ( $this->cookie as $c ) {
+ $serialized = $c->serializeToHttpRequest( $path,
$domain );
+
+ if ( $serialized ) {
+ $cookies[] = $serialized;
+ }
+ }
+
+ return implode( '; ', $cookies );
+ }
+
+ /**
+ * Parse the content of an Set-Cookie HTTP Response header.
+ *
+ * @param string $cookie
+ * @param string $domain Cookie's domain
+ * @return null
+ */
+ public function parseCookieResponseHeader( $cookie, $domain ) {
+ $len = strlen( 'Set-Cookie:' );
+
+ if ( substr_compare( 'Set-Cookie:', $cookie, 0, $len, true )
=== 0 ) {
+ $cookie = substr( $cookie, $len );
+ }
+
+ $bit = array_map( 'trim', explode( ';', $cookie ) );
+
+ if ( count( $bit ) >= 1 ) {
+ list( $name, $value ) = explode( '=', array_shift( $bit
), 2 );
+ $attr = [];
+
+ foreach ( $bit as $piece ) {
+ $parts = explode( '=', $piece );
+ if ( count( $parts ) > 1 ) {
+ $attr[strtolower( $parts[0] )] =
$parts[1];
+ } else {
+ $attr[strtolower( $parts[0] )] = true;
+ }
+ }
+
+ if ( !isset( $attr['domain'] ) ) {
+ $attr['domain'] = $domain;
+ } elseif ( !Cookie::validateCookieDomain(
$attr['domain'], $domain ) ) {
+ return null;
+ }
+
+ $this->setCookie( $name, $value, $attr );
+ }
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/281267
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie98eadb2a8015f1290447b79cc095799abaeba4f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits