forked from njones/socketio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.go
42 lines (37 loc) · 1.1 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
package socketio
import (
"context"
"net/http"
"net/url"
)
// Request is a wrapped HTTP request object so that we expose only the things that are necessary,
type Request struct {
r *http.Request
Method string
URL *url.URL
Header http.Header
Host string
RemoteAddr string
RequestURI string
}
func (req *Request) Cookie(name string) (*http.Cookie, error) { return req.r.Cookie(name) }
func (req *Request) Cookies() []*http.Cookie { return req.r.Cookies() }
func (req *Request) Context() context.Context { return req.r.Context() }
func (req *Request) Referer() string { return req.r.Referer() }
func (req *Request) UserAgent() string { return req.r.UserAgent() }
func (req *Request) WithContext(ctx context.Context) *Request {
req.r = req.r.WithContext(ctx)
return req
}
func sioRequest(r *http.Request) *Request {
req := &Request{
r: r,
Method: r.Method,
URL: r.URL,
Header: r.Header,
Host: r.Host,
RemoteAddr: r.RemoteAddr,
RequestURI: r.RequestURI,
}
return req
}