-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.go
72 lines (59 loc) · 1.37 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
package jeen
import (
"net/http"
"strings"
"github.com/go-chi/chi/v5"
)
type Request struct {
instance *http.Request
}
// create new request instance
func newRequest(r *http.Request) *Request {
return &Request{
instance: r,
}
}
// return instance of *http.Request
func (r *Request) Instance() *http.Request {
return r.instance
}
func (r *Request) IsTLS() bool {
return r.instance.TLS != nil
}
func (r *Request) RemoteAddr() string {
return r.instance.RemoteAddr
}
func (r *Request) RequestURI() string {
return r.instance.RequestURI
}
func (r *Request) URLParam(key string) string {
return chi.URLParam(r.instance, key)
}
func (r *Request) QueryParam(name string) string {
return r.instance.URL.Query().Get(name)
}
func (r *Request) QueryString() string {
return r.instance.URL.RawQuery
}
func (r *Request) IsWebSocket() bool {
upgrade := r.instance.Header.Get("Upgrade")
return strings.EqualFold(upgrade, "websocket")
}
func (r *Request) Scheme() string {
if r.IsTLS() {
return "https"
}
if scheme := r.instance.Header.Get("X-Forwarded-Proto"); scheme != "" {
return scheme
}
if scheme := r.instance.Header.Get("X-Forwarded-Protocol"); scheme != "" {
return scheme
}
if ssl := r.instance.Header.Get("X-Forwarded-Ssl"); ssl == "on" {
return "https"
}
if scheme := r.instance.Header.Get("X-Url-Scheme"); scheme != "" {
return scheme
}
return "http"
}