@@ -105,42 +105,36 @@ func requestHandler(ctx *fasthttp.RequestCtx) {
105
105
106
106
// log.Println(string(ctx.Path()), string(ctx.Host()), ctx.String(), "\r\n\r\n", ctx.Request.String())
107
107
108
- host := string (ctx .Host ())
109
- if len (host ) < 1 {
110
- ctx .SetStatusCode (fasthttp .StatusBadRequest )
111
- log .Println ("Reject: Empty host" )
112
- return
113
- }
114
-
115
- hostname , port , err := net .SplitHostPort (host )
116
- if err != nil {
117
- if err1 , ok := err .(* net.AddrError ); ok && strings .Index (err1 .Err , "missing port" ) != - 1 {
118
- hostname , port , err = net .SplitHostPort (host + ":80" )
119
- }
108
+ // https connecttion
109
+ if bytes .Equal (ctx .Method (), []byte ("CONNECT" )) {
110
+ host := string (ctx .RequestURI ())
111
+ hostname , port , err := net .SplitHostPort (host )
120
112
if err != nil {
121
- ctx .SetStatusCode (fasthttp .StatusBadRequest )
122
- log .Println ("Reject: Invalid host" , host , err )
123
- return
113
+ if err1 , ok := err .(* net.AddrError ); ok && strings .Index (err1 .Err , "missing port" ) != - 1 {
114
+ hostname , port , err = net .SplitHostPort (host + ":80" )
115
+ }
116
+ if err != nil {
117
+ ctx .SetStatusCode (fasthttp .StatusBadRequest )
118
+ log .Println ("Reject: Invalid host" , host , err )
119
+ return
120
+ }
124
121
}
125
- }
126
122
127
- cacheAddrMapLock .RLock ()
128
- tcpAddr , ok := cacheTCPAddrMap [host ]
129
- cacheAddrMapLock .RUnlock ()
130
- if ok == false {
131
- tcpAddr , err = getUsableIP (hostname , port )
132
- if err != nil {
133
- ctx .SetStatusCode (fasthttp .StatusInternalServerError )
134
- log .Println ("No usable IP:" , host , err )
135
- return
123
+ cacheAddrMapLock .RLock ()
124
+ tcpAddr , ok := cacheTCPAddrMap [host ]
125
+ cacheAddrMapLock .RUnlock ()
126
+ if ok == false {
127
+ tcpAddr , err = getUsableIP (hostname , port )
128
+ if err != nil {
129
+ ctx .SetStatusCode (fasthttp .StatusInternalServerError )
130
+ log .Println ("No usable IP:" , host , err )
131
+ return
132
+ }
133
+ cacheAddrMapLock .Lock ()
134
+ cacheTCPAddrMap [host ] = tcpAddr
135
+ cacheAddrMapLock .Unlock ()
136
136
}
137
- cacheAddrMapLock .Lock ()
138
- cacheTCPAddrMap [host ] = tcpAddr
139
- cacheAddrMapLock .Unlock ()
140
- }
141
137
142
- // https connecttion
143
- if bytes .Equal (ctx .Method (), []byte ("CONNECT" )) {
144
138
err = httpsHandler (ctx , hostname , tcpAddr )
145
139
if err != nil {
146
140
ctx .SetStatusCode (fasthttp .StatusInternalServerError )
@@ -149,10 +143,10 @@ func requestHandler(ctx *fasthttp.RequestCtx) {
149
143
return
150
144
}
151
145
152
- err = httpClient .DoTimeout (& ctx .Request , & ctx .Response , httpClientTimeout )
146
+ err : = httpClient .DoTimeout (& ctx .Request , & ctx .Response , httpClientTimeout )
153
147
if err != nil {
154
148
ctx .SetStatusCode (fasthttp .StatusInternalServerError )
155
- log .Println ("httpHandler:" , host , err )
149
+ log .Println ("httpHandler:" , string ( ctx . Host ()) , err )
156
150
}
157
151
}
158
152
0 commit comments