-
Notifications
You must be signed in to change notification settings - Fork 3
/
request.go
executable file
·73 lines (66 loc) · 1.3 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
package httpKit
import (
"net/http"
)
// GetRoute 获取: 路由(不带query).
/*
e.g.
http://127.0.0.1/a/b?1=1&2=2 => "/a/b"
*/
func GetRoute(req *http.Request) string {
return req.URL.Path
}
// GetRouteWithQuery 获取: 路由(带query).
/*
e.g.
http://127.0.0.1/a/b?1=1&2=2 => "/a/b?1=1&2=2"
*/
func GetRouteWithQuery(req *http.Request) string {
return req.RequestURI
}
// GetURLRawQuery
/*
e.g.
http://127.0.0.1/a/b?1=1&2=2 => "1=1&2=2"
*/
func GetURLRawQuery(req *http.Request) string {
return req.URL.RawQuery
}
// GetProto
/*
@return "HTTP/1.0" || "HTTP/1.1" || ...
*/
func GetProto(req *http.Request) string {
return req.Proto
}
// GetRequestUrl 返回当前接口的url.
/*
PS: 包括query、fragment.
*/
func GetRequestUrl(req *http.Request) string {
return req.URL.String()
//url := req.URL
//
///* scheme */
//var scheme string
//if strKit.IsEmpty(url.Scheme) {
// if websocket.IsWebSocketUpgrade(req) {
// scheme = operationKit.Ternary(req.TLS != nil, "wss", "ws")
// } else {
// scheme = operationKit.Ternary(req.TLS != nil, "https", "http")
// }
//} else {
// scheme = url.Scheme
//}
//
///* host */
//host := url.Host
//if strKit.IsEmpty(host) {
// host = req.Host
//}
//
///* path */
//path := url.Path
//
//return fmt.Sprintf("%s://%s%s", scheme, host, path)
}