This repository has been archived by the owner on Jul 6, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Request.go
84 lines (69 loc) · 1.75 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
package aero
import (
stdContext "context"
"net/http"
)
// Request is an interface for HTTP requests.
type Request interface {
Body() RequestBody
Context() stdContext.Context
Header(string) string
Host() string
Internal() *http.Request
Method() string
Path() string
Protocol() string
Scheme() string
}
// request represents the HTTP request used in the given context.
type request struct {
inner *http.Request
}
// Body represents the request body.
func (req *request) Body() RequestBody {
return RequestBody{
reader: req.inner.Body,
}
}
// Context returns the request context.
func (req *request) Context() stdContext.Context {
return req.inner.Context()
}
// Header returns the header value for the given key.
func (req *request) Header(key string) string {
return req.inner.Header.Get(key)
}
// Method returns the request method.
func (req *request) Method() string {
return req.inner.Method
}
// Protocol returns the request protocol.
func (req *request) Protocol() string {
return req.inner.Proto
}
// Host returns the requested host.
func (req *request) Host() string {
return req.inner.Host
}
// Path returns the requested path.
func (req *request) Path() string {
return req.inner.URL.Path
}
// Scheme returns http or https depending on what scheme has been used.
func (req *request) Scheme() string {
scheme := req.inner.Header.Get("X-Forwarded-Proto")
if scheme != "" {
return scheme
}
if req.inner.TLS != nil {
return "https"
}
return "http"
}
// Internal returns the underlying *http.Request.
// This method should be avoided unless absolutely necessary
// because Aero doesn't guarantee that the underlying framework
// will always stay net/http based in the future.
func (req *request) Internal() *http.Request {
return req.inner
}