r106948 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106947‎ | r106948 | r106949 >
Date:15:31, 21 December 2011
Author:hashar
Status:ok (Comments)
Tags:
Comment:
tests for r94881 which interprets relative Location: headers
Modified paths:
  • /trunk/phase3/tests/phpunit/includes/HttpTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/HttpTest.php
@@ -124,4 +124,49 @@
125125 );
126126 }
127127
 128+ function testRelativeRedirections() {
 129+ $h = new MWHttpRequestTester( 'http://oldsite/file.ext' );
 130+ # Forge a Location header
 131+ $h->setRespHeaders( 'location', array(
 132+ 'http://newsite/file.ext',
 133+ '/newfile.ext',
 134+ )
 135+ );
 136+ # Verify we correctly fix the Location
 137+ $this->assertEquals(
 138+ 'http://newsite/newfile.ext',
 139+ $h->getFinalUrl(),
 140+ "Relative file path Location: interpreted as full URL"
 141+ );
 142+
 143+ $h->setRespHeaders( 'location', array(
 144+ 'https://oldsite/file.ext'
 145+ )
 146+ );
 147+ $this->assertEquals(
 148+ 'https://oldsite/file.ext',
 149+ $h->getFinalUrl(),
 150+ "Location to the HTTPS version of the site"
 151+ );
 152+
 153+ $h->setRespHeaders( 'location', array(
 154+ '/anotherfile.ext',
 155+ 'http://anotherfile/hoster.ext',
 156+ 'https://anotherfile/hoster.ext'
 157+ )
 158+ );
 159+ $this->assertEquals(
 160+ 'https://anotherfile/hoster.ext',
 161+ $h->getFinalUrl( "Relative file path Location: should keep the latest host and scheme!")
 162+ );
 163+ }
128164 }
 165+
 166+/**
 167+ * Class to let us overwrite MWHttpREquest respHeaders variable
 168+ */
 169+class MWHttpRequestTester extends MWHttpRequest {
 170+ function setRespHeaders( $name, $value ) {
 171+ $this->respHeaders[$name] = $value ;
 172+ }
 173+}

Follow-up revisions

RevisionCommit summaryAuthorDate
r107121Add comments explaining that the funky multiple Location headers stuff is a C...brion23:12, 22 December 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r94881Relative values of the "Location" header are incorrect as stated in RFC, howe...marooned10:33, 18 August 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   19:29, 21 December 2011

This looks wrong; you'll never have multiple Location: header values in a real response. See my comment on the original code which I've marked fixme because it looks wrong: https://www.mediawiki.org/wiki/Special:Code/MediaWiki/94881#c28231

#Comment by Hashar (talk | contribs)   12:53, 22 December 2011

Yeah it is a bit surprising to have multiple headers. A full explanation is at: https://www.mediawiki.org/wiki/Special:Code/MediaWiki/94881#c28317

#Comment by Marooned~mediawikiwiki (talk | contribs)   10:02, 22 December 2011

As I've answered you under 94881, I stumbled upon some real page giving me multiple Location headers. Hence the fix.

#Comment by Brion VIBBER (talk | contribs)   23:13, 22 December 2011

Added an explanatory comment in r107121 -- the multiple headers are a CURL artifact.

Status & tagging log