Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.7] Do not save the url in session if the call is prefetch #27017

Merged
merged 1 commit into from
Jan 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Illuminate/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,17 @@ public function pjax()
return $this->headers->get('X-PJAX') == true;
}

/**
* Determine if the request is the result of an prefetch call.
*
* @return bool
*/
public function prefetch()
{
return strcasecmp($this->server->get('HTTP_X_MOZ'), 'prefetch') === 0 ||
strcasecmp($this->headers->get('Purpose'), 'prefetch') === 0;
}

/**
* Determine if the request is over HTTPS.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Session/Middleware/StartSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ protected function configHitsLottery(array $config)
*/
protected function storeCurrentUrl(Request $request, $session)
{
if ($request->method() === 'GET' && $request->route() && ! $request->ajax()) {
if ($request->method() === 'GET' && $request->route() && ! $request->ajax() && ! $request->prefetch()) {
$session->setPreviousUrl($request->fullUrl());
}
}
Expand Down
22 changes: 22 additions & 0 deletions tests/Http/HttpRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,28 @@ public function testAjaxMethod()
$this->assertFalse($request->ajax());
}

public function testPrefetchMethod()
{
$request = Request::create('/', 'GET');
$this->assertFalse($request->prefetch());

$request->server->set('HTTP_X_MOZ', '');
$this->assertFalse($request->prefetch());
$request->server->set('HTTP_X_MOZ', 'prefetch');
$this->assertTrue($request->prefetch());
$request->server->set('HTTP_X_MOZ', 'Prefetch');
$this->assertTrue($request->prefetch());

$request->server->remove('HTTP_X_MOZ');

$request->headers->set('Purpose', '');
$this->assertFalse($request->prefetch());
$request->headers->set('Purpose', 'prefetch');
$this->assertTrue($request->prefetch());
$request->headers->set('Purpose', 'Prefetch');
$this->assertTrue($request->prefetch());
}

public function testPjaxMethod()
{
$request = Request::create('/', 'GET', [], [], [], ['HTTP_X_PJAX' => 'true'], '{}');
Expand Down