Added GetBody(), IsPost() to context
This commit is contained in:
parent
39050c1654
commit
c08c7d9b41
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue