-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrequest.go
91 lines (73 loc) · 1.47 KB
/
request.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package hblade
import (
"bytes"
stdContext "context"
"io/ioutil"
"net/http"
"github.com/zatxm/hblade/tools"
)
type Request interface {
RawData() ([]byte, error)
RawDataSetBody() ([]byte, error)
Context() stdContext.Context
Header(string) string
Host() string
Method() string
Path() string
Protocol() string
Scheme() string
RawQuery() string
ContentType() string
Req() *http.Request
}
type request struct {
req *http.Request
}
func (r *request) RawData() (b []byte, err error) {
return tools.ReadAll(r.req.Body)
}
func (r *request) RawDataSetBody() (b []byte, err error) {
b, err = tools.ReadAll(r.req.Body)
if err != nil {
return
}
r.req.Body = ioutil.NopCloser(bytes.NewBuffer(b))
return
}
func (r *request) Context() stdContext.Context {
return r.req.Context()
}
func (r *request) Header(key string) string {
return r.req.Header.Get(key)
}
func (r *request) Method() string {
return r.req.Method
}
func (r *request) Protocol() string {
return r.req.Proto
}
func (r *request) Host() string {
return r.req.Host
}
func (r *request) Path() string {
return r.req.URL.Path
}
func (r *request) RawQuery() string {
return r.req.URL.RawQuery
}
func (r *request) Scheme() string {
scheme := r.Header("X-Forwarded-Proto")
if scheme != "" {
return scheme
}
if r.req.TLS != nil {
return "https"
}
return "http"
}
func (r *request) ContentType() string {
return filterFlags(r.Header("Content-Type"))
}
func (r *request) Req() *http.Request {
return r.req
}