@@ -541,28 +541,94 @@ available (@racket[make-secret-salt/file]),
541541
542542@defmodule[web-server/http/redirect]{
543543
544- @defproc[(redirect-to [uri non-empty-string?]
545- [perm/temp redirection-status? temporarily]
546- [#:headers headers (listof header?) (list)])
547- response?]{
548- Generates an HTTP response that redirects the browser to @racket[uri],
549- while including the @racket[headers] in the response.
550-
551- Example:
552- @racket[(redirect-to "http://www.add-three-numbers.com " permanently)]
553- }
554-
555- @defproc[(redirection-status? [v any/c])
556- boolean?]{
557- Determines if @racket[v] is one of the following values.
558- }
559-
560- @defthing[permanently redirection-status?]{A @racket[redirection-status?] for permanent redirections.}
561-
562- @defthing[temporarily redirection-status?]{A @racket[redirection-status?] for temporary redirections.}
563-
564- @defthing[see-other redirection-status?]{A @racket[redirection-status?] for "see-other " redirections.}
565-
544+ @deftogether[
545+ (@defproc[(redirect-to [uri non-empty-string?]
546+ [status redirection-status? temporarily]
547+ [#:headers headers (listof header?) '() ])
548+ response?]
549+ @defproc[(redirection-status? [v any/c]) boolean?]
550+ @defthing[temporarily redirection-status?]
551+ @defthing[temporarily/same-method redirection-status?]
552+ @defthing[see-other redirection-status?]
553+ @defthing[permanently redirection-status?])]{
554+ The function @racket[redirect-to]
555+ generates an HTTP response that redirects the browser to @racket[uri],
556+ while including the @racket[headers] in the response.
557+ The @racket[status] argument is a @deftech{redirection status}
558+ value, which determines the specific type of HTTP redirect to be used.
559+
560+ The default @tech{redirection status}, @racket[temporarily],
561+ is preserved for backwards compatibility:
562+ new code should usually use either @racket[temporarily/same-method]
563+ or @racket[see-other], instead.
564+ The @racket[temporarily] @tech{redirection status} corresponds to
565+ @hyperlink["https://tools.ietf.org/html/rfc7231#section-6.4.3 " ]{
566+ @litchar{302 Found}}.
567+ Unfortunately, browsers have not implemented this status consistently
568+ for methods other than @litchar{GET} and (in practice, with all but some
569+ very old browsers) @litchar{POST}.
570+
571+ The @racket[temporarily/same-method] @tech{redirection status}
572+ uses @hyperlink["https://tools.ietf.org/html/rfc7231#section-6.4.7 " ]{
573+ @litchar{307 Temporary Redirect}}.
574+ This redirects the browser to @racket[uri] using the same HTTP method
575+ as the original request.
576+
577+ The @racket[see-other] @tech{redirection status} corresponds to
578+ @hyperlink["https://tools.ietf.org/html/rfc7231#section-6.4.4 " ]{
579+ @litchar{303 See Other}}.
580+ It is most often used to implement the @deftech{Post-Redirect-Get}
581+ pattern: as a response to a request using @litchar{POST} or
582+ another HTTP method with side-effects, it causes the browser to
583+ perform a @litchar{GET} or @litchar{HEAD} request for @racket[uri],
584+ which gives a response to the original @litchar{POST} request.
585+ This prevents the @onscreen{Back} and @onscreen{Refresh} buttons
586+ from duplicating effects, such as making a purchase or
587+ adding items to a database.
588+ The web server provides @racket[redirect/get] for added convienience
589+ with @tech{Post-Redirect-Get}.
590+
591+ The @racket[permanently] @tech{redirection status} uses the HTTP status
592+ @hyperlink["https://tools.ietf.org/html/rfc7231#section-6.4.2 " ]{
593+ @litchar{301 Moved Permanently}}.
594+ It is like @racket[temporarily], except that, as the name suggests,
595+ it signifies that the move is permanent and that search engines,
596+ for example, should use @racket[uri] instead of the URI of the
597+ orriginal request.
598+ Unfortunately, @racket[permanently] is also like @racket[temporarily]
599+ in that browsers have implemented it inconsistently for
600+ methods other than @litchar{GET} and @litchar{HEAD}:
601+ in particular, @hyperlink["https://tools.ietf.org/html/rfc7231#section-6.4.2 " ]{
602+ RFC 7231 } permits that, ``for historical reasons, a user agent @bold{may}
603+ change the request method from @litchar{POST} to @litchar{GET} for the subsequent request.
604+ When it is important to ensure that the request to @racket[uri] use the same method,
605+ there are some possible alternatives:
606+ @itemlist[
607+ @item{RFC 7231 suggests using @litchar{307 Temporary Redirect},
608+ i.e. @racket[temporarily/same-method].
609+ This has the disadvantage that search engines and others won't
610+ update references to the old URI.}
611+ @item{@hyperlink["https://tools.ietf.org/html/rfc7538 " ]{RFC 7538 }
612+ specifies a new HTTP status, @litchar{308 Permanent Redirect},
613+ which fobids changing the request method, analagously to
614+ @litchar{307 Temporary Redirect}.
615+ However, the RFC also highlights some important
616+ @hyperlink["https://tools.ietf.org/html/rfc7538#section-4 " ]{
617+ deployment considerations} for this status.
618+ In particular, older browsers---including, as of this writing,
619+ some that remain in
620+ @hyperlink["https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308#Browser_compatibility " ]{
621+ relatively common use}---do not understand this status and will
622+ fall back to the semantics of
623+ @hyperlink["https://tools.ietf.org/html/rfc7231#section-6.4.1 " ]{
624+ @litchar{300 Multiple Choices}}, which is often undesirable.}
625+ @item{The application can note the method of the original request
626+ and use @racket[permanently] for @litchar{GET} and @litchar{HEAD} requests
627+ or one of the other alternatives for other methods.}]
628+
629+ Example:
630+ @racket[(redirect-to "http://www.add-three-numbers.com " permanently)]
631+ }
566632}
567633
568634@; ------------------------------------------------------------
0 commit comments