<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[25044] trunk/src/wp-includes/class-http.php: WP_HTTP: Cookies: Fill the defaults for the Cookie object based on the current requested URL.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/25044">25044</a></dd>
<dt>Author</dt> <dd>dd32</dd>
<dt>Date</dt> <dd>2013-08-17 00:33:39 +0000 (Sat, 17 Aug 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>WP_HTTP: Cookies: Fill the defaults for the Cookie object based on the current requested URL. Fixes <a href="http://core.trac.wordpress.org/ticket/21182">#21182</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesclasshttpphp">trunk/src/wp-includes/class-http.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesclasshttpphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/class-http.php (25043 => 25044)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/class-http.php     2013-08-16 22:41:23 UTC (rev 25043)
+++ trunk/src/wp-includes/class-http.php        2013-08-17 00:33:39 UTC (rev 25044)
</span><span class="lines">@@ -158,7 +158,7 @@
</span><span class="cx">                  $r['headers'] = array();
</span><span class="cx"> 
</span><span class="cx">          if ( ! is_array( $r['headers'] ) ) {
</span><del>-                       $processedHeaders = WP_Http::processHeaders( $r['headers'] );
</del><ins>+                        $processedHeaders = WP_Http::processHeaders( $r['headers'], $url );
</ins><span class="cx">                   $r['headers'] = $processedHeaders['headers'];
</span><span class="cx">          }
</span><span class="cx"> 
</span><span class="lines">@@ -349,10 +349,11 @@
</span><span class="cx">   * @since 2.7.0
</span><span class="cx">   *
</span><span class="cx">   * @param string|array $headers
</span><ins>+        * @param string $url The URL that was requested
</ins><span class="cx">    * @return array Processed string headers. If duplicate headers are encountered,
</span><span class="cx">   *                                      Then a numbered array is returned as the value of that header-key.
</span><span class="cx">   */
</span><del>-       public static function processHeaders($headers) {
</del><ins>+        public static function processHeaders( $headers, $url ) {
</ins><span class="cx">           // split headers, one per array element
</span><span class="cx">          if ( is_string($headers) ) {
</span><span class="cx">                  // tolerate line terminator: CRLF = LF (RFC 2616 19.3)
</span><span class="lines">@@ -400,7 +401,7 @@
</span><span class="cx">                          $newheaders[ $key ] = $value;
</span><span class="cx">                  }
</span><span class="cx">                  if ( 'set-cookie' == $key )
</span><del>-                               $cookies[] = new WP_Http_Cookie( $value );
</del><ins>+                                $cookies[] = new WP_Http_Cookie( $value, $url );
</ins><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">          return array('response' => $response, 'headers' => $newheaders, 'cookies' => $cookies);
</span><span class="lines">@@ -857,7 +858,7 @@
</span><span class="cx">          if ( true === $secure_transport )
</span><span class="cx">                  error_reporting($error_reporting);
</span><span class="cx"> 
</span><del>-               $arrHeaders = WP_Http::processHeaders( $process['headers'] );
</del><ins>+                $arrHeaders = WP_Http::processHeaders( $process['headers'], $url );
</ins><span class="cx"> 
</span><span class="cx">          $response = array(
</span><span class="cx">                  'headers' => $arrHeaders['headers'],
</span><span class="lines">@@ -1051,9 +1052,9 @@
</span><span class="cx"> 
</span><span class="cx">          $processedHeaders = array();
</span><span class="cx">          if ( isset( $meta['wrapper_data']['headers'] ) )
</span><del>-                       $processedHeaders = WP_Http::processHeaders($meta['wrapper_data']['headers']);
</del><ins>+                        $processedHeaders = WP_Http::processHeaders( $meta['wrapper_data']['headers'], $url );
</ins><span class="cx">           else
</span><del>-                       $processedHeaders = WP_Http::processHeaders($meta['wrapper_data']);
</del><ins>+                        $processedHeaders = WP_Http::processHeaders( $meta['wrapper_data'], $url );
</ins><span class="cx"> 
</span><span class="cx">          $response = array(
</span><span class="cx">                  'headers' => $processedHeaders['headers'],
</span><span class="lines">@@ -1301,7 +1302,7 @@
</span><span class="cx">          }
</span><span class="cx"> 
</span><span class="cx">          $theResponse = curl_exec( $handle );
</span><del>-               $theHeaders = WP_Http::processHeaders( $this->headers );
</del><ins>+                $theHeaders = WP_Http::processHeaders( $this->headers, $url );
</ins><span class="cx">           $theBody = $this->body;
</span><span class="cx"> 
</span><span class="cx">          $this->headers = '';
</span><span class="lines">@@ -1667,14 +1668,23 @@
</span><span class="cx">   * <li>Expires - (optional) String or int (UNIX timestamp).</li>
</span><span class="cx">   * <li>Path (optional)</li>
</span><span class="cx">   * <li>Domain (optional)</li>
</span><ins>+        * <li>Port (optional)</li>
</ins><span class="cx">    * </ol>
</span><span class="cx">   *
</span><span class="cx">   * @access public
</span><span class="cx">   * @since 2.8.0
</span><span class="cx">   *
</span><span class="cx">   * @param string|array $data Raw cookie data.
</span><ins>+        * @param string $requested_url The URL which the cookie was set on, used for default 'domain' and 'port' values
</ins><span class="cx">    */
</span><del>-       function __construct( $data ) {
</del><ins>+        function __construct( $data, $requested_url = '' ) {
+               $arrURL = @parse_url( $requested_url );
+               if ( isset( $arrURL['host'] ) )
+                       $this->domain = $arrURL['host'];
+               $this->path = isset( $arrURL['path'] ) ? $arrURL['path'] : '/';
+               if (  '/' != substr( $this->path, -1 ) )
+                       $this->path = dirname( $this->path ) . '/';
+
</ins><span class="cx">           if ( is_string( $data ) ) {
</span><span class="cx">                  // Assume it's a header string direct from a previous request
</span><span class="cx">                  $pairs = explode( ';', $data );
</span><span class="lines">@@ -1703,10 +1713,10 @@
</span><span class="cx">                          return false;
</span><span class="cx"> 
</span><span class="cx">                  // Set properties based directly on parameters
</span><del>-                       $this->name   = $data['name'];
-                       $this->value  = isset( $data['value'] ) ? $data['value'] : '';
-                       $this->path   = isset( $data['path'] ) ? $data['path'] : '';
-                       $this->domain = isset( $data['domain'] ) ? $data['domain'] : '';
</del><ins>+                        foreach ( array( 'name', 'value', 'path', 'domain', 'port' ) as $field ) {
+                               if ( isset( $data[ $field ] ) )
+                                       $this->$field = $data[ $field ];
+                       }
</ins><span class="cx"> 
</span><span class="cx">                  if ( isset( $data['expires'] ) )
</span><span class="cx">                          $this->expires = is_int( $data['expires'] ) ? $data['expires'] : strtotime( $data['expires'] );
</span><span class="lines">@@ -1727,18 +1737,21 @@
</span><span class="cx">   * @return boolean true if allowed, false otherwise.
</span><span class="cx">   */
</span><span class="cx">  function test( $url ) {
</span><ins>+               if ( is_null( $this->name ) )
+                       return false;
+
</ins><span class="cx">           // Expires - if expired then nothing else matters
</span><span class="cx">          if ( isset( $this->expires ) && time() > $this->expires )
</span><span class="cx">                  return false;
</span><span class="cx"> 
</span><span class="cx">          // Get details on the URL we're thinking about sending to
</span><span class="cx">          $url = parse_url( $url );
</span><del>-               $url['port'] = isset( $url['port'] ) ? $url['port'] : 80;
</del><ins>+                $url['port'] = isset( $url['port'] ) ? $url['port'] : ( 'https' == $url['scheme'] ? 443 : 80 );
</ins><span class="cx">           $url['path'] = isset( $url['path'] ) ? $url['path'] : '/';
</span><span class="cx"> 
</span><span class="cx">          // Values to use for comparison against the URL
</span><span class="cx">          $path   = isset( $this->path )   ? $this->path   : '/';
</span><del>-               $port   = isset( $this->port )   ? $this->port   : 80;
</del><ins>+                $port   = isset( $this->port )   ? $this->port   : null;
</ins><span class="cx">           $domain = isset( $this->domain ) ? strtolower( $this->domain ) : strtolower( $url['host'] );
</span><span class="cx">          if ( false === stripos( $domain, '.' ) )
</span><span class="cx">                  $domain .= '.local';
</span><span class="lines">@@ -1749,7 +1762,7 @@
</span><span class="cx">                  return false;
</span><span class="cx"> 
</span><span class="cx">          // Port - supports "port-lists" in the format: "80,8000,8080"
</span><del>-               if ( !in_array( $url['port'], explode( ',', $port) ) )
</del><ins>+                if ( !empty( $port ) && !in_array( $url['port'], explode( ',', $port) ) )
</ins><span class="cx">                   return false;
</span><span class="cx"> 
</span><span class="cx">          // Path - request path must start with path restriction
</span></span></pre>
</div>
</div>

</body>
</html>