Commit f531d9de authored by alexpott's avatar alexpott
Browse files

Issue #355157 by valthebald, urbanape: Fixed 302 response code from...

Issue #355157 by valthebald, urbanape: Fixed 302 response code from drupal_redirect_form() violates HTTP/1.1 spec.
parent 9875f435
......@@ -169,7 +169,10 @@ public function redirectForm($form_state) {
}
$form_state['redirect_route']->setAbsolute();
return new RedirectResponse($form_state['redirect_route']->toString());
// According to RFC 7231, 303 See Other status code must be used
// to redirect user agent (and not default 302 Found).
// @see http://tools.ietf.org/html/rfc7231#section-6.4.4
return new RedirectResponse($form_state['redirect_route']->toString(), Response::HTTP_SEE_OTHER);
}
// Only invoke a redirection if redirect value was not set to FALSE.
......@@ -188,7 +191,7 @@ public function redirectForm($form_state) {
$status_code = $form_state['redirect'][2];
}
else {
$status_code = 302;
$status_code = Response::HTTP_SEE_OTHER;
}
return new RedirectResponse($this->urlGenerator->generateFromPath($form_state['redirect'][0], $options), $status_code);
}
......@@ -200,7 +203,7 @@ public function redirectForm($form_state) {
install_goto($form_state['redirect']);
}
else {
return new RedirectResponse($this->urlGenerator->generateFromPath($form_state['redirect'], array('absolute' => TRUE)));
return new RedirectResponse($this->urlGenerator->generateFromPath($form_state['redirect'], array('absolute' => TRUE)), Response::HTTP_SEE_OTHER);
}
}
}
......@@ -211,7 +214,7 @@ public function redirectForm($form_state) {
'query' => $request->query->all(),
'absolute' => TRUE,
));
return new RedirectResponse($url);
return new RedirectResponse($url, Response::HTTP_SEE_OTHER);
}
}
......
......@@ -108,7 +108,7 @@ function testInternalBrowser() {
$this->assertNotEqual($old_user_id, $this->container->get('current_user')->id(), 'Current user service updated.');
$headers = $this->drupalGetHeaders(TRUE);
$this->assertEqual(count($headers), 2, 'There was one intermediate request.');
$this->assertTrue(strpos($headers[0][':status'], '302') !== FALSE, 'Intermediate response code was 302.');
$this->assertTrue(strpos($headers[0][':status'], '303') !== FALSE, 'Intermediate response code was 303.');
$this->assertFalse(empty($headers[0]['location']), 'Intermediate request contained a Location header.');
$this->assertEqual($this->getUrl(), $headers[0]['location'], 'HTTP redirect was followed');
$this->assertFalse($this->drupalGetHeader('Location'), 'Headers from intermediate request were reset.');
......
......@@ -116,7 +116,7 @@ public function providerTestHandleFormSubmissionWithResponses() {
*
* @dataProvider providerTestRedirectWithResult
*/
public function testRedirectWithResult($form_state, $result, $status = 302) {
public function testRedirectWithResult($form_state, $result, $status = 303) {
$form_submitter = $this->getFormSubmitter();
$this->urlGenerator->expects($this->once())
->method('generateFromPath')
......@@ -141,7 +141,7 @@ public function testRedirectWithResult($form_state, $result, $status = 302) {
*
* @dataProvider providerTestRedirectWithRouteWithResult
*/
public function testRedirectWithRouteWithResult($form_state, $result, $status = 302) {
public function testRedirectWithRouteWithResult($form_state, $result, $status = 303) {
$container = new ContainerBuilder();
$container->set('url_generator', $this->urlGenerator);
\Drupal::setContainer($container);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment