Skip to content

Commit

Permalink
Fixed fasthttp Request#SetBody
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Rana <[email protected]>
  • Loading branch information
vishr committed May 1, 2016
1 parent 0edb17e commit 368f2ab
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
5 changes: 2 additions & 3 deletions engine/fasthttp/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io"
"mime/multipart"

"github.com/labstack/echo"
"github.com/labstack/echo/engine"
"github.com/labstack/gommon/log"
"github.com/valyala/fasthttp"
Expand Down Expand Up @@ -95,12 +94,12 @@ func (r *Request) SetURI(uri string) {

// Body implements `engine.Request#Body` function.
func (r *Request) Body() io.Reader {
return bytes.NewBuffer(r.PostBody())
return bytes.NewBuffer(r.Request.Body())
}

// SetBody implements `engine.Request#SetBody` function.
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.
Expand Down
3 changes: 2 additions & 1 deletion glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions middleware/body_limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ func TestBodyLimit(t *testing.T) {
rec := test.NewResponseRecorder()
c := e.NewContext(req, rec)
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))
}

Expand All @@ -28,6 +31,9 @@ func TestBodyLimit(t *testing.T) {
assert.Equal(t, "Hello, World!", rec.Body.String())

// Overlimit
// BodyLimit("2B")(h)(c)
// assert.Equal(t, "Hello, World!", rec.Body.String())
req = test.NewRequest(echo.POST, "/", bytes.NewReader([]byte("Hello, World!")))
rec = test.NewResponseRecorder()
c = e.NewContext(req, rec)
BodyLimit("2B")(h)(c)
assert.Equal(t, http.StatusRequestEntityTooLarge, rec.Status())
}

0 comments on commit 368f2ab

Please sign in to comment.