Make WordPress Core


Ignore:
Timestamp:
08/17/2013 12:33:39 AM (13 years ago)
Author:
dd32
Message:

WP_HTTP: Cookies: Fill the defaults for the Cookie object based on the current requested URL. Fixes #21182

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-http.php

    r25016 r25044  
    159159
    160160                if ( ! is_array( $r['headers'] ) ) {
    161                         $processedHeaders = WP_Http::processHeaders( $r['headers'] );
     161                        $processedHeaders = WP_Http::processHeaders( $r['headers'], $url );
    162162                        $r['headers'] = $processedHeaders['headers'];
    163163                }
    … …  
    350350         *
    351351         * @param string|array $headers
     352         * @param string $url The URL that was requested
    352353         * @return array Processed string headers. If duplicate headers are encountered,
    353354         *                                      Then a numbered array is returned as the value of that header-key.
    354355         */
    355         public static function processHeaders($headers) {
     356        public static function processHeaders( $headers, $url ) {
    356357                // split headers, one per array element
    357358                if ( is_string($headers) ) {
    … …  
    401402                        }
    402403                        if ( 'set-cookie' == $key )
    403                                 $cookies[] = new WP_Http_Cookie( $value );
     404                                $cookies[] = new WP_Http_Cookie( $value, $url );
    404405                }
    405406
    … …  
    858859                        error_reporting($error_reporting);
    859860
    860                 $arrHeaders = WP_Http::processHeaders( $process['headers'] );
     861                $arrHeaders = WP_Http::processHeaders( $process['headers'], $url );
    861862
    862863                $response = array(
    … …  
    10521053                $processedHeaders = array();
    10531054                if ( isset( $meta['wrapper_data']['headers'] ) )
    1054                         $processedHeaders = WP_Http::processHeaders($meta['wrapper_data']['headers']);
     1055                        $processedHeaders = WP_Http::processHeaders( $meta['wrapper_data']['headers'], $url );
    10551056                else
    1056                         $processedHeaders = WP_Http::processHeaders($meta['wrapper_data']);
     1057                        $processedHeaders = WP_Http::processHeaders( $meta['wrapper_data'], $url );
    10571058
    10581059                $response = array(
    … …  
    13021303
    13031304                $theResponse = curl_exec( $handle );
    1304                 $theHeaders = WP_Http::processHeaders( $this->headers );
     1305                $theHeaders = WP_Http::processHeaders( $this->headers, $url );
    13051306                $theBody = $this->body;
    13061307
    … …  
    16681669         * <li>Path (optional)</li>
    16691670         * <li>Domain (optional)</li>
     1671         * <li>Port (optional)</li>
    16701672         * </ol>
    16711673         *
    … …  
    16741676         *
    16751677         * @param string|array $data Raw cookie data.
    1676          */
    1677         function __construct( $data ) {
     1678         * @param string $requested_url The URL which the cookie was set on, used for default 'domain' and 'port' values
     1679         */
     1680        function __construct( $data, $requested_url = '' ) {
     1681                $arrURL = @parse_url( $requested_url );
     1682                if ( isset( $arrURL['host'] ) )
     1683                        $this->domain = $arrURL['host'];
     1684                $this->path = isset( $arrURL['path'] ) ? $arrURL['path'] : '/';
     1685                if (  '/' != substr( $this->path, -1 ) )
     1686                        $this->path = dirname( $this->path ) . '/';
     1687
    16781688                if ( is_string( $data ) ) {
    16791689                        // Assume it's a header string direct from a previous request
    … …  
    17041714
    17051715                        // Set properties based directly on parameters
    1706                         $this->name   = $data['name'];
    1707                         $this->value  = isset( $data['value'] ) ? $data['value'] : '';
    1708                         $this->path   = isset( $data['path'] ) ? $data['path'] : '';
    1709                         $this->domain = isset( $data['domain'] ) ? $data['domain'] : '';
     1716                        foreach ( array( 'name', 'value', 'path', 'domain', 'port' ) as $field ) {
     1717                                if ( isset( $data[ $field ] ) )
     1718                                        $this->$field = $data[ $field ];
     1719                        }
    17101720
    17111721                        if ( isset( $data['expires'] ) )
    … …  
    17281738         */
    17291739        function test( $url ) {
     1740                if ( is_null( $this->name ) )
     1741                        return false;
     1742
    17301743                // Expires - if expired then nothing else matters
    17311744                if ( isset( $this->expires ) && time() > $this->expires )
    … …  
    17341747                // Get details on the URL we're thinking about sending to
    17351748                $url = parse_url( $url );
    1736                 $url['port'] = isset( $url['port'] ) ? $url['port'] : 80;
     1749                $url['port'] = isset( $url['port'] ) ? $url['port'] : ( 'https' == $url['scheme'] ? 443 : 80 );
    17371750                $url['path'] = isset( $url['path'] ) ? $url['path'] : '/';
    17381751
    17391752                // Values to use for comparison against the URL
    17401753                $path   = isset( $this->path )   ? $this->path   : '/';
    1741                 $port   = isset( $this->port )   ? $this->port   : 80;
     1754                $port   = isset( $this->port )   ? $this->port   : null;
    17421755                $domain = isset( $this->domain ) ? strtolower( $this->domain ) : strtolower( $url['host'] );
    17431756                if ( false === stripos( $domain, '.' ) )
    … …  
    17501763
    17511764                // Port - supports "port-lists" in the format: "80,8000,8080"
    1752                 if ( !in_array( $url['port'], explode( ',', $port) ) )
     1765                if ( !empty( $port ) && !in_array( $url['port'], explode( ',', $port) ) )
    17531766                        return false;
    17541767
Note: See TracChangeset for help on using the changeset viewer.