Added GetBody(), IsPost() to context

This commit is contained in:
DataHoarder 2022-01-31 12:48:31 +01:00
parent 39050c1654
commit c08c7d9b41

View file

@ -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()