Added GetBody(), IsPost() to context
This commit is contained in:
parent
39050c1654
commit
c08c7d9b41
|
@ -1,8 +1,10 @@
|
||||||
package httputils
|
package httputils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"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 {
|
func (c *RequestContext) IsGet() bool {
|
||||||
if c.fasthttp != nil {
|
if c.fasthttp != nil {
|
||||||
return c.fasthttp.IsGet()
|
return c.fasthttp.IsGet()
|
||||||
|
@ -177,6 +192,16 @@ func (c *RequestContext) IsGet() bool {
|
||||||
return false
|
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 {
|
func (c *RequestContext) IsOptions() bool {
|
||||||
if c.fasthttp != nil {
|
if c.fasthttp != nil {
|
||||||
return c.fasthttp.IsOptions()
|
return c.fasthttp.IsOptions()
|
||||||
|
|
Loading…
Reference in a new issue