http: Add an HTTP redirect senteniel error

This commit is contained in:
Sasha Koshka 2024-12-10 21:32:12 -05:00
parent bf668b0cf7
commit efc3fc0990
2 changed files with 19 additions and 0 deletions

View File

@ -179,6 +179,12 @@ func (this *Handler) serveDocument (
this.serveError (
res, req,
httpError.Status, httpError.Message, false)
return
}
var httpRedirect Redirect
if errors.As(err, &httpRedirect) {
http.Redirect(res, req, httpRedirect.Location, httpRedirect.Status)
return
}
if err != nil {
this.serveError (

View File

@ -22,6 +22,19 @@ func (err Error) Error () string {
}
}
// Redirect, if returned from a template, will cause the server to redirect the
// client to the given location.
type Redirect struct {
Status int
Location string
}
func (err Redirect) Error () string {
return fmt.Sprintf (
"%d: %s: %s",
err.Status, http.StatusText(err.Status), err.Location)
}
// HTTPData represents information about an ongoing HTTP request that is made
// available to templates as they are being executed.
type HTTPData struct {