mirror of
https://github.com/labstack/echo.git
synced 2024-11-24 08:22:21 +02:00
Handle invalid status code in Context.Redirect
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
4dcb57d42a
commit
523ac4a9a0
@ -7,8 +7,9 @@ import (
|
||||
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/net/websocket"
|
||||
"net/url"
|
||||
|
||||
"golang.org/x/net/websocket"
|
||||
)
|
||||
|
||||
type (
|
||||
@ -171,6 +172,9 @@ func (c *Context) NoContent(code int) error {
|
||||
|
||||
// Redirect redirects the request using http.Redirect with status code.
|
||||
func (c *Context) Redirect(code int, url string) error {
|
||||
if code < http.StatusMultipleChoices || code > http.StatusTemporaryRedirect {
|
||||
return InvalidRedirectCode
|
||||
}
|
||||
http.Redirect(c.response, c.request, url, code)
|
||||
return nil
|
||||
}
|
||||
|
8
echo.go
8
echo.go
@ -153,7 +153,7 @@ var (
|
||||
|
||||
UnsupportedMediaType = errors.New("echo ⇒ unsupported media type")
|
||||
RendererNotRegistered = errors.New("echo ⇒ renderer not registered")
|
||||
|
||||
InvalidRedirectCode = errors.New("echo ⇒ invalid redirect status code")
|
||||
//----------------
|
||||
// Error handlers
|
||||
//----------------
|
||||
@ -196,15 +196,15 @@ func New() (e *Echo) {
|
||||
http.Error(c.response, msg, code)
|
||||
}
|
||||
e.SetHTTPErrorHandler(e.defaultHTTPErrorHandler)
|
||||
e.SetBinder(func(r *http.Request, v interface{}) error {
|
||||
e.SetBinder(func(r *http.Request, v interface{}) (err error) {
|
||||
ct := r.Header.Get(ContentType)
|
||||
err := UnsupportedMediaType
|
||||
err = UnsupportedMediaType
|
||||
if strings.HasPrefix(ct, ApplicationJSON) {
|
||||
err = json.NewDecoder(r.Body).Decode(v)
|
||||
} else if strings.HasPrefix(ct, ApplicationXML) {
|
||||
err = xml.NewDecoder(r.Body).Decode(v)
|
||||
}
|
||||
return err
|
||||
return
|
||||
})
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user