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

Skip to content

Commit 7a28a44

Browse files
committed
[BrowserKit] Emulate back/forward browser navigation
1 parent 549af73 commit 7a28a44

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Symfony/Component/BrowserKit/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ CHANGELOG
77
* [BC BREAK] The request method is dropped from POST to GET when the response
88
status code is 301.
99

10+
* [BC BREAK] Client will skip redirects during history navigation
11+
(back and forward calls) according to W3C Browsers recommendation
12+
1013
3.2.0
1114
-----
1215

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ abstract class Client
4242

4343
private $maxRedirects = -1;
4444
private $redirectCount = 0;
45+
private $redirects = array();
4546
private $isMainRequest = true;
4647

4748
/**
@@ -328,6 +329,8 @@ public function request($method, $uri, array $parameters = array(), array $files
328329
}
329330

330331
if ($this->followRedirects && $this->redirect) {
332+
$this->redirects[spl_object_hash($this->history->current())] = true;
333+
331334
return $this->crawler = $this->followRedirect();
332335
}
333336

@@ -430,7 +433,11 @@ protected function createCrawlerFromContent($uri, $content, $type)
430433
*/
431434
public function back()
432435
{
433-
return $this->requestFromRequest($this->history->back(), false);
436+
do {
437+
$request = $this->history->back();
438+
} while (array_key_exists(spl_object_hash($request), $this->redirects));
439+
440+
return $this->requestFromRequest($request, false);
434441
}
435442

436443
/**
@@ -440,7 +447,11 @@ public function back()
440447
*/
441448
public function forward()
442449
{
443-
return $this->requestFromRequest($this->history->forward(), false);
450+
do {
451+
$request = $this->history->forward();
452+
} while (array_key_exists(spl_object_hash($request), $this->redirects));
453+
454+
return $this->requestFromRequest($request, false);
444455
}
445456

446457
/**

0 commit comments

Comments
 (0)