github.com/TeaOSLab/EdgeNode@v1.3.8/internal/nodes/http_client_transport.go (about) 1 // Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn . 2 3 package nodes 4 5 import ( 6 "net/http" 7 ) 8 9 const emptyHTTPLocation = "/$EmptyHTTPLocation$" 10 11 type HTTPClientTransport struct { 12 *http.Transport 13 } 14 15 func (this *HTTPClientTransport) RoundTrip(req *http.Request) (*http.Response, error) { 16 resp, err := this.Transport.RoundTrip(req) 17 if err != nil { 18 return resp, err 19 } 20 21 // 检查在跳转相关状态中Location是否存在 22 if httpStatusIsRedirect(resp.StatusCode) && len(resp.Header.Get("Location")) == 0 { 23 resp.Header.Set("Location", emptyHTTPLocation) 24 } 25 return resp, nil 26 }