3 Star 16 Fork 3

Gitee 极速下载 / go-tagexpr

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/bytedance/go-tagexpr/
克隆/下载
request.go 1.55 KB
一键复制 编辑 原始数据 按行查看 历史
package binding
import (
"bytes"
"io"
"net/http"
"net/url"
)
type Request interface {
GetMethod() string
GetQuery() url.Values
GetContentType() string
GetHeader() http.Header
GetCookies() []*http.Cookie
GetBody() ([]byte, error)
GetPostForm() (url.Values, error)
GetForm() (url.Values, error)
}
func wrapRequest(req *http.Request) Request {
r := &httpRequest{
Request: req,
}
if getBodyCodec(r) == bodyForm && req.PostForm == nil {
b, _ := r.GetBody()
if b != nil {
req.ParseMultipartForm(defaultMaxMemory)
}
}
return r
}
type httpRequest struct {
*http.Request
}
func (r *httpRequest) GetMethod() string {
return r.Method
}
func (r *httpRequest) GetQuery() url.Values {
return r.URL.Query()
}
func (r *httpRequest) GetContentType() string {
return r.GetHeader().Get("Content-Type")
}
func (r *httpRequest) GetHeader() http.Header {
return r.Header
}
func (r *httpRequest) GetCookies() []*http.Cookie {
return r.Cookies()
}
func (r *httpRequest) GetBody() ([]byte, error) {
body, _ := r.Body.(*Body)
if body != nil {
body.Reset()
return body.bodyBytes, nil
}
switch r.Method {
case "POST", "PUT", "PATCH", "DELETE":
var buf bytes.Buffer
_, err := io.Copy(&buf, r.Body)
r.Body.Close()
if err != nil {
return nil, err
}
body = &Body{
Buffer: &buf,
bodyBytes: buf.Bytes(),
}
r.Body = body
return body.bodyBytes, nil
default:
return nil, nil
}
}
func (r *httpRequest) GetPostForm() (url.Values, error) {
return r.PostForm, nil
}
func (r *httpRequest) GetForm() (url.Values, error) {
return r.Form, nil
}
1
https://gitee.com/mirrors/go-tagexpr.git
git@gitee.com:mirrors/go-tagexpr.git
mirrors
go-tagexpr
go-tagexpr
v2.7.4

搜索帮助

53164aa7 5694891 3bd8fe86 5694891