5050
5151 env = logger .GetEnv ()
5252
53- client = new (http.Client )
53+ client = & http.Client {
54+ Timeout : TIMEOUT ,
55+ }
5456)
5557
5658type OverLimit struct {
@@ -140,8 +142,7 @@ func handleMethod(u, method string) error {
140142}
141143
142144func handleResponse (c * gin.Context , resp * http.Response ) {
143- reader := resp .Body
144- defer reader .Close ()
145+ defer resp .Body .Close ()
145146
146147 contentLength := resp .ContentLength
147148 contentType := resp .Header .Get ("Content-Type" )
@@ -151,7 +152,7 @@ func handleResponse(c *gin.Context, resp *http.Response) {
151152 headers [k ] = strings .Join (v , ", " )
152153 }
153154
154- c .DataFromReader (resp .StatusCode , contentLength , contentType , reader , headers )
155+ c .DataFromReader (resp .StatusCode , contentLength , contentType , resp . Body , headers )
155156}
156157
157158func handleDownloadResponse (
@@ -229,9 +230,8 @@ func handleInvalidResponse(c *gin.Context, resp *http.Response) error {
229230}
230231
231232func 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
235235 }
236236
237237 c .Request .Header .Del ("Host" )
@@ -327,12 +327,9 @@ func handler(c *gin.Context) {
327327 return
328328 }
329329
330- log .Debug ().Str ("url" , u ).Msg ("Got a request from client " )
330+ log .Debug ().Str ("url" , u ).Msg ("Got a request from remote " )
331331
332- switch {
333- case checkURL (u ):
334- log .Trace ().Msg ("URL 有效" )
335- default :
332+ if ! checkURL (u ) {
336333 c .JSON (http .StatusBadRequest , newErrorResponse (ErrInvalidInput ))
337334 return
338335 }
0 commit comments