mirror of
https://github.com/labstack/echo.git
synced 2024-12-24 20:14:31 +02:00
Context#Redirect
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
4f6fd9725d
commit
c8725ae244
@ -285,13 +285,13 @@ func (c *context) NoContent(code int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Redirect redirects the request using http.Redirect with status code.
|
||||
// Redirect redirects the request with status code.
|
||||
func (c *context) Redirect(code int, url string) error {
|
||||
if code < http.StatusMultipleChoices || code > http.StatusTemporaryRedirect {
|
||||
return ErrInvalidRedirectCode
|
||||
}
|
||||
// TODO: v2
|
||||
// http.Redirect(c.response, c.request, url, code)
|
||||
c.response.Header().Set(Location, url)
|
||||
c.response.WriteHeader(code)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -171,18 +171,20 @@ func TestContext(t *testing.T) {
|
||||
rec = test.NewResponseRecorder()
|
||||
c = NewContext(req, rec, e)
|
||||
c.NoContent(http.StatusOK)
|
||||
assert.Equal(t, http.StatusOK, c.Response().Status())
|
||||
assert.Equal(t, http.StatusOK, rec.Status())
|
||||
|
||||
// Redirect
|
||||
rec = test.NewResponseRecorder()
|
||||
c = NewContext(req, rec, e)
|
||||
assert.Equal(t, nil, c.Redirect(http.StatusMovedPermanently, "http://labstack.github.io/echo"))
|
||||
assert.Equal(t, "http://labstack.github.io/echo", rec.Header().Get(Location))
|
||||
assert.Equal(t, http.StatusMovedPermanently, rec.Status())
|
||||
|
||||
// Error
|
||||
rec = test.NewResponseRecorder()
|
||||
c = NewContext(req, rec, e).Object()
|
||||
c = NewContext(req, rec, e)
|
||||
c.Error(errors.New("error"))
|
||||
assert.Equal(t, http.StatusInternalServerError, c.Response().Status())
|
||||
assert.Equal(t, http.StatusInternalServerError, rec.Status())
|
||||
|
||||
// reset
|
||||
c.Object().reset(req, test.NewResponseRecorder())
|
||||
|
12
glide.lock
generated
12
glide.lock
generated
@ -1,27 +1,27 @@
|
||||
hash: f220137e9ccd9aaf3051be33c3c23ea8abd2c40df6cf96175c3994d482b5e007
|
||||
updated: 2016-02-18T22:26:06.777493855-08:00
|
||||
updated: 2016-02-20T12:46:29.282847891-08:00
|
||||
imports:
|
||||
- name: github.com/klauspost/compress
|
||||
version: 3dcfad3351d86b2c07406ac93e92f03edd98c707
|
||||
version: f9625351863b5e94c1da72862187b8fe9a91af90
|
||||
subpackages:
|
||||
- flate
|
||||
- gzip
|
||||
- zlib
|
||||
- name: github.com/klauspost/cpuid
|
||||
version: 349c675778172472f5e8f3a3e0fe187e302e5a10
|
||||
version: 2c698c6aef5976c7860074cc7040e8af7866aa21
|
||||
- name: github.com/klauspost/crc32
|
||||
version: 81ac41837f877bc6a7f81321c2c29d88d69c108a
|
||||
version: 19b0b332c9e4516a6370a0456e6182c3b5036720
|
||||
- name: github.com/labstack/gommon
|
||||
version: bfff5bf04688a4048a5cb4dd3b3f0697caaad19c
|
||||
subpackages:
|
||||
- color
|
||||
- log
|
||||
- name: github.com/mattn/go-colorable
|
||||
version: 9fdad7c47650b7d2e1da50644c1f4ba7f172f252
|
||||
version: 9cbef7c35391cca05f15f8181dc0b18bc9736dbb
|
||||
- name: github.com/mattn/go-isatty
|
||||
version: 56b76bdf51f7708750eac80fa38b952bb9f32639
|
||||
- name: github.com/valyala/fasthttp
|
||||
version: 14b2ff3d2b38a596b037541c94f43718d9da215f
|
||||
version: 58e4dea85db1b01e95b02e105b2a0e953c52694a
|
||||
- name: golang.org/x/net
|
||||
version: b6d7b1396ec874c3b00f6c84cd4301a17c56c8ed
|
||||
subpackages:
|
||||
|
Loading…
Reference in New Issue
Block a user