50
50
51
51
env = logger .GetEnv ()
52
52
53
- client = new (http.Client )
53
+ client = & http.Client {
54
+ Timeout : TIMEOUT ,
55
+ }
54
56
)
55
57
56
58
type OverLimit struct {
@@ -140,8 +142,7 @@ func handleMethod(u, method string) error {
140
142
}
141
143
142
144
func handleResponse (c * gin.Context , resp * http.Response ) {
143
- reader := resp .Body
144
- defer reader .Close ()
145
+ defer resp .Body .Close ()
145
146
146
147
contentLength := resp .ContentLength
147
148
contentType := resp .Header .Get ("Content-Type" )
@@ -151,7 +152,7 @@ func handleResponse(c *gin.Context, resp *http.Response) {
151
152
headers [k ] = strings .Join (v , ", " )
152
153
}
153
154
154
- c .DataFromReader (resp .StatusCode , contentLength , contentType , reader , headers )
155
+ c .DataFromReader (resp .StatusCode , contentLength , contentType , resp . Body , headers )
155
156
}
156
157
157
158
func handleDownloadResponse (
@@ -229,9 +230,8 @@ func handleInvalidResponse(c *gin.Context, resp *http.Response) error {
229
230
}
230
231
231
232
func proxy (c * gin.Context , u string , followRedirect bool ) error {
232
- err := handleMethod (u , c .Request .Method )
233
- if err != nil {
234
- return err
233
+ if c .Request .Method != http .MethodGet && c .Request .Method != http .MethodPost {
234
+ return ErrMethod
235
235
}
236
236
237
237
c .Request .Header .Del ("Host" )
@@ -327,12 +327,9 @@ func handler(c *gin.Context) {
327
327
return
328
328
}
329
329
330
- log .Debug ().Str ("url" , u ).Msg ("Got a request from client " )
330
+ log .Debug ().Str ("url" , u ).Msg ("Got a request from remote " )
331
331
332
- switch {
333
- case checkURL (u ):
334
- log .Trace ().Msg ("URL 有效" )
335
- default :
332
+ if ! checkURL (u ) {
336
333
c .JSON (http .StatusBadRequest , newErrorResponse (ErrInvalidInput ))
337
334
return
338
335
}
0 commit comments