Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0d07af8

Browse files
committed
[BrowserKit] Pass headers when followRedirect() is called
1 parent 939f872 commit 0d07af8

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ public function followRedirect()
420420
throw new \LogicException('The request was not redirected.');
421421
}
422422

423-
return $this->request('get', $this->redirect);
423+
return $this->request('get', $this->redirect, array(), array(), $this->history->current()->getServer());
424424
}
425425

426426
/**

src/Symfony/Component/BrowserKit/Tests/ClientTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,33 @@ public function testFollowRedirectWithCookies()
342342
$this->assertEquals(array('foo' => 'bar'), $client->getRequest()->getCookies());
343343
}
344344

345+
public function testFollowRedirectWithHeaders()
346+
{
347+
$headers = array(
348+
'HTTP_HOST' => 'www.example.com',
349+
'HTTP_USER_AGENT' => 'Symfony2 BrowserKit',
350+
'CONTENT_TYPE' => 'application/vnd.custom+xml',
351+
'HTTPS' => false,
352+
);
353+
354+
$client = new TestClient();
355+
$client->followRedirects(false);
356+
$client->setNextResponse(new Response('', 302, array(
357+
'Location' => 'http://www.example.com/redirected',
358+
)));
359+
$client->request('GET', 'http://www.example.com/', array(), array(), array(
360+
'CONTENT_TYPE' => 'application/vnd.custom+xml',
361+
));
362+
363+
$this->assertEquals($headers, $client->getRequest()->getServer());
364+
365+
$client->followRedirect();
366+
367+
$headers['HTTP_REFERER'] = 'http://www.example.com/';
368+
369+
$this->assertEquals($headers, $client->getRequest()->getServer());
370+
}
371+
345372
public function testBack()
346373
{
347374
$client = new TestClient();

0 commit comments

Comments
 (0)