Browse Source

merged branch ktomk/patch-1 (PR #1558)

Commits
-------

db37bbb HTTP 1.1 / RFC 2616 - Make Redirect response HTTP body having a HTML body.

Discussion
----------

[HttpFoundation] Redirect response is missing a HTML body

HTTP 1.1 / RFC 2616 - Make Redirect response HTTP body having a HTML body as "...the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s)." (unless HEAD request, see response codes 301, 302, 303 and 307).

See [10.3 Redirection 3xx *in* Hypertext Transfer Protocol -- HTTP/1.1 (RFC 2616 Fielding, et al.)](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3) and [9.3 Redirection 3xx *in* Hypertext Transfer Protocol -- HTTP/1.0](http://tools.ietf.org/html/rfc1945#section-9.3).

---------------------------------------------------------------------------

by stloyd at 2011/07/06 10:50:50 -0700

As we allow changing protocol version, and by [default](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Response.php#L88) use 1.0 this should have an use also `$this->getProtocolVersion()`.

---------------------------------------------------------------------------

by ktomk at 2011/07/06 10:57:48 -0700

(Updated the original comment and linked the HTTP 1.0 specs in there)

Just have reviewed the RFCs and the processing inside `[HttpFoundation]`.  The response class [identifies the following status codes as redirects](https://github.com/ktomk/symfony/blob/db37bbb189dd90f2abd352a29b732be03f75c92b/src/Symfony/Component/HttpFoundation/Response.php#L741): `201`, `301`, `302`, `303` and `307`. That's quite the same list I compiled above where I did only check for 3xx codes. In HTTP/1.0 (symfony default) the 201 response can contain the new location in it's entity (body) of the response (in contrast, [RFC 1945 is *not* talking about the location header explicitly](http://tools.ietf.org/html/rfc1945#section-9.2); see as well [10.11  Location](http://tools.ietf.org/html/rfc1945#section-10.11), that's [in HTTP/1.1 done](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.2), compare [14.30 Location](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30)).

So I would say HTTP 1.0 is properly reflected with the changes as well and the concrete Response object [is already taking care for protocol validity](https://github.com/ktomk/symfony/blob/db37bbb189dd90f2abd352a29b732be03f75c92b/src/Symfony/Component/HttpFoundation/RedirectResponse.php#L41).
Fabien Potencier 14 years ago
parent
commit
c41da9d447
1 changed files with 1 additions and 1 deletions
  1. 1 1
      src/Symfony/Component/HttpFoundation/RedirectResponse.php

+ 1 - 1
src/Symfony/Component/HttpFoundation/RedirectResponse.php

@@ -33,7 +33,7 @@ class RedirectResponse extends Response
         }
 
         parent::__construct(
-            sprintf('<html><head><meta http-equiv="refresh" content="1;url=%s"/></head></html>', htmlspecialchars($url, ENT_QUOTES)),
+            sprintf('<html><head><meta http-equiv="refresh" content="1;url=%s"/></head><body>Redirect to <a href="%1$s">%1$s</a>.</body></html>', htmlspecialchars($url, ENT_QUOTES)),
             $status,
             array('Location' => $url)
         );