-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnativeresponse.go
78 lines (60 loc) · 1.46 KB
/
nativeresponse.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
package reverseproxy
import (
"io"
"net/http"
)
var _ Context = &NativeResponse{}
type NativeResponse struct {
RespWriter http.ResponseWriter
*http.Request
isDead bool
}
func (n *NativeResponse) SetBody(body []byte) {
n.RespWriter.Write(body)
}
func (n *NativeResponse) SetStatusCode(code int) {
n.RespWriter.WriteHeader(code)
}
func (n *NativeResponse) Redirect(url string, code int) {
http.Redirect(n.RespWriter, n.Request, url, code)
}
func (n *NativeResponse) SetHeader(key string, value string) {
n.RespWriter.Header().Set(key, value)
}
func (n *NativeResponse) GetHeader(key string) string {
return n.RespWriter.Header().Get(key)
}
func (n *NativeResponse) RequestURI() string {
return n.Request.URL.RequestURI()
}
func (n *NativeResponse) RequestPath() string {
return n.Request.URL.Path
}
func (n *NativeResponse) RequestMethod() string {
return n.Request.Method
}
func (n *NativeResponse) RemoteAddr() string {
return n.Request.RemoteAddr
}
func (n *NativeResponse) QueryValue(key string) string {
return n.Request.URL.Query().Get(key)
}
func (n *NativeResponse) QueryValues(key string) []string {
q := n.Request.URL.Query()
if v, ok := q[key]; ok {
return v
}
return []string{}
}
func (n *NativeResponse) ResponseWriter() io.Writer {
return n.RespWriter
}
func (n *NativeResponse) RequestHost() string {
return n.Request.Host
}
func (n *NativeResponse) IsDead() bool {
return n.isDead
}
func (n *NativeResponse) SetDead(on bool) {
n.isDead = on
}