1
0
mirror of https://github.com/labstack/echo.git synced 2025-01-12 01:22:21 +02:00

Fixed fasthttp Request#SetBody

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2016-04-30 21:56:35 -07:00
parent 0edb17e978
commit 368f2ab67e
3 changed files with 13 additions and 7 deletions

View File

@ -7,7 +7,6 @@ import (
"io" "io"
"mime/multipart" "mime/multipart"
"github.com/labstack/echo"
"github.com/labstack/echo/engine" "github.com/labstack/echo/engine"
"github.com/labstack/gommon/log" "github.com/labstack/gommon/log"
"github.com/valyala/fasthttp" "github.com/valyala/fasthttp"
@ -95,12 +94,12 @@ func (r *Request) SetURI(uri string) {
// Body implements `engine.Request#Body` function. // Body implements `engine.Request#Body` function.
func (r *Request) Body() io.Reader { func (r *Request) Body() io.Reader {
return bytes.NewBuffer(r.PostBody()) return bytes.NewBuffer(r.Request.Body())
} }
// SetBody implements `engine.Request#SetBody` function. // SetBody implements `engine.Request#SetBody` function.
func (r *Request) SetBody(reader io.Reader) { func (r *Request) SetBody(reader io.Reader) {
r.SetBodyStream(reader, r.header.Get(echo.HeaderContentType)) r.Request.SetBodyStream(reader, 0)
} }
// FormValue implements `engine.Request#FormValue` function. // FormValue implements `engine.Request#FormValue` function.

3
glide.lock generated
View File

@ -1,5 +1,5 @@
hash: 21820434709470e49c64df0f854d3352088ca664d193e29bc6cd434518c27a7c hash: 21820434709470e49c64df0f854d3352088ca664d193e29bc6cd434518c27a7c
updated: 2016-04-30T19:53:13.742557404-07:00 updated: 2016-04-30T20:20:55.32592199-07:00
imports: imports:
- name: github.com/dgrijalva/jwt-go - name: github.com/dgrijalva/jwt-go
version: a2c85815a77d0f951e33ba4db5ae93629a1530af version: a2c85815a77d0f951e33ba4db5ae93629a1530af
@ -18,6 +18,7 @@ imports:
subpackages: subpackages:
- color - color
- log - log
- bytes
- name: github.com/mattn/go-colorable - name: github.com/mattn/go-colorable
version: bc69d6cebca8dd5675346a34a1c545b67dc74d5e version: bc69d6cebca8dd5675346a34a1c545b67dc74d5e
- name: github.com/mattn/go-isatty - name: github.com/mattn/go-isatty

View File

@ -18,7 +18,10 @@ func TestBodyLimit(t *testing.T) {
rec := test.NewResponseRecorder() rec := test.NewResponseRecorder()
c := e.NewContext(req, rec) c := e.NewContext(req, rec)
h := func(c echo.Context) error { h := func(c echo.Context) error {
body, _ := ioutil.ReadAll(c.Request().Body()) body, err := ioutil.ReadAll(c.Request().Body())
if err != nil {
return err
}
return c.String(http.StatusOK, string(body)) return c.String(http.StatusOK, string(body))
} }
@ -28,6 +31,9 @@ func TestBodyLimit(t *testing.T) {
assert.Equal(t, "Hello, World!", rec.Body.String()) assert.Equal(t, "Hello, World!", rec.Body.String())
// Overlimit // Overlimit
// BodyLimit("2B")(h)(c) req = test.NewRequest(echo.POST, "/", bytes.NewReader([]byte("Hello, World!")))
// assert.Equal(t, "Hello, World!", rec.Body.String()) rec = test.NewResponseRecorder()
c = e.NewContext(req, rec)
BodyLimit("2B")(h)(c)
assert.Equal(t, http.StatusRequestEntityTooLarge, rec.Status())
} }