diff --git a/httputils/context.go b/httputils/context.go index 518e410..ca227ee 100644 --- a/httputils/context.go +++ b/httputils/context.go @@ -1,8 +1,10 @@ package httputils import ( + "bytes" "fmt" "github.com/valyala/fasthttp" + "io" "net/http" "time" ) @@ -167,6 +169,19 @@ func (c *RequestContext) DoRedirect(location string, code int) { } } +func (c *RequestContext) GetBody() io.Reader { + if c.fasthttp != nil { + b := c.fasthttp.Request.Body() + buf := make([]byte, len(b)) + copy(buf, b) + return bytes.NewBuffer(buf) + } else if c.httpRequest != nil { + return c.httpRequest.Body + } + + return nil +} + func (c *RequestContext) IsGet() bool { if c.fasthttp != nil { return c.fasthttp.IsGet() @@ -177,6 +192,16 @@ func (c *RequestContext) IsGet() bool { return false } +func (c *RequestContext) IsPost() bool { + if c.fasthttp != nil { + return c.fasthttp.IsPost() + } else if c.httpRequest != nil { + return c.httpRequest.Method == "POST" + } + + return false +} + func (c *RequestContext) IsOptions() bool { if c.fasthttp != nil { return c.fasthttp.IsOptions()