diff --git a/http/handler.go b/http/handler.go index 2256080..d5bb723 100644 --- a/http/handler.go +++ b/http/handler.go @@ -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 ( diff --git a/http/http.go b/http/http.go index b3b7ab6..f3438f6 100644 --- a/http/http.go +++ b/http/http.go @@ -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 {