"Hashar" posted a comment on MediaWiki.r94881.
URL: http://www.mediawiki.org/wiki/Special:Code/MediaWiki/94881#c28317

Commit summary for MediaWiki.r94881:

Relative values of the "Location" header are incorrect as stated in RFC, 
however they do happen and modern browsers support them.
This function loops backwards through all locations in order to build the 
proper absolute URI - Marooned at wikia-inc.com

Hashar's comment:

By setting CURLOPT_HEADERFUNCTION we can pass any header to a callback:

        $this->curlOptions[CURLOPT_HEADERFUNCTION] = array( $this, "readHeader" 
);

The callback just append received header one after the other in a huge string. 
It is then exploded by \r\n to an array.
    protected function readHeader( $fh, $content ) {
        $this->headerText .= $content;
                         ^^^^
        return strlen( $content );
    }

So internally, the Location: header content is really an array of any Location: 
lines curl might have encountered while following redirections.


I have setup a testing env on my computer using existing virtual hosts and just 
creating dummy PHP redirection files.

http://trunk.dev/redir.php redirects to <tt>http://mw18.dev/redir.php</tt>
http://mw18.dev/redir.php redirects to <tt>/landing.php</tt>

h = MWHttpRequest::factory( 'http://trunk.dev/redir.php', array( 
'followRedirects'=>true) );
$h->execute();
print $h->getFinalUrl();

The header representation for 'location' is:
    [location] => Array
        (
            [0] => http://mw18.dev/redir.php
            [1] => /landing.php
        )

So previously we would receive <tt>/landing.php</tt> as a Location and one 
could assume it is relative to the requested URL host (<tt>trunk.dev</tt>) 
whereas it is relative to the host of the previous URL having a host.



_______________________________________________
MediaWiki-CodeReview mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-codereview

Reply via email to