■ ■ ■ ■ ■ ■
pkg/protocols/http/retryhttpclient/client.go
| skipped 8 lines |
9 | 9 | | "net" |
10 | 10 | | "net/http" |
11 | 11 | | "net/http/cookiejar" |
| 12 | + | "net/http/httptrace" |
12 | 13 | | "net/url" |
13 | 14 | | "regexp" |
14 | 15 | | "runtime" |
| skipped 146 lines |
161 | 162 | | |
162 | 163 | | // target |
163 | 164 | | target = fmt.Sprintf("%s://%s", u.Scheme, u.Host) |
164 | | - | targetfull := fulltarget(fmt.Sprintf("%s://%s", u.Scheme, u.Host), u.Path) |
165 | | - | if targetfull != target { |
166 | | - | target = targetfull |
| 165 | + | if !strings.HasPrefix(rule.Request.Path, "^") { |
| 166 | + | targetfull := fulltarget(fmt.Sprintf("%s://%s", u.Scheme, u.Host), u.Path) |
| 167 | + | if targetfull != target { |
| 168 | + | target = targetfull |
| 169 | + | } |
167 | 170 | | } |
168 | 171 | | |
169 | 172 | | // path |
170 | 173 | | rule.Request.Path = setVariableMap(strings.TrimSpace(rule.Request.Path), variableMap) |
| 174 | + | if !strings.HasPrefix(rule.Request.Path, "^") { |
| 175 | + | target = strings.TrimRight(target, "/") + rule.Request.Path |
| 176 | + | } else { |
| 177 | + | target = strings.TrimRight(target, "/") + "/" + rule.Request.Path[1:] |
| 178 | + | } |
171 | 179 | | // rule.Request.Path = strings.ReplaceAll(rule.Request.Path, " ", "%20") |
172 | 180 | | // rule.Request.Path = strings.ReplaceAll(rule.Request.Path, "+", "%20") |
173 | 181 | | |
| skipped 9 lines |
183 | 191 | | } |
184 | 192 | | |
185 | 193 | | // newhttprequest |
186 | | - | req, err := retryablehttp.NewRequest(rule.Request.Method, strings.TrimRight(target, "/")+rule.Request.Path, nil) |
| 194 | + | req, err := retryablehttp.NewRequest(rule.Request.Method, target, nil) |
187 | 195 | | if len(rule.Request.Body) > 0 { |
188 | | - | req, err = retryablehttp.NewRequest(rule.Request.Method, strings.TrimRight(target, "/")+rule.Request.Path, strings.NewReader(rule.Request.Body)) |
| 196 | + | req, err = retryablehttp.NewRequest(rule.Request.Method, target, strings.NewReader(rule.Request.Body)) |
189 | 197 | | } |
190 | 198 | | if err != nil { |
191 | 199 | | return err |
| skipped 15 lines |
207 | 215 | | req.Header.Add("User-Agent", utils.RandomUA()) |
208 | 216 | | } |
209 | 217 | | |
| 218 | + | // latency |
| 219 | + | var milliseconds int64 |
| 220 | + | start := time.Now() |
| 221 | + | trace := httptrace.ClientTrace{} |
| 222 | + | trace.GotFirstResponseByte = func() { |
| 223 | + | milliseconds = time.Since(start).Nanoseconds() / 1e6 |
| 224 | + | } |
| 225 | + | req = req.WithContext(httptrace.WithClientTrace(req.Context(), &trace)) |
| 226 | + | |
210 | 227 | | // http client do request |
211 | 228 | | resp := &http.Response{} |
212 | 229 | | if !rule.Request.FollowRedirects { |
| skipped 39 lines |
252 | 269 | | protoResp.Body = []byte(utf8RespBody) |
253 | 270 | | protoResp.Raw = []byte(resp.Proto + " " + resp.Status + "\n" + strings.Trim(rawHeaderBuilder.String(), "\n") + "\n\n" + utf8RespBody) |
254 | 271 | | protoResp.RawHeader = []byte(strings.Trim(rawHeaderBuilder.String(), "\n")) |
| 272 | + | protoResp.Latency = milliseconds |
255 | 273 | | variableMap["response"] = protoResp |
256 | 274 | | |
257 | 275 | | // store the request |
| skipped 16 lines |
274 | 292 | | protoReq.ContentType = req.Header.Get("Content-Type") |
275 | 293 | | protoReq.Body = []byte(rule.Request.Body) |
276 | 294 | | |
277 | | - | reqPath := strings.Replace(utils.UrlTypeToString(protoResp.Url), strings.TrimRight(target, "/"), "", 1) |
| 295 | + | reqPath := strings.Replace(target, fmt.Sprintf("%s://%s", u.Scheme, u.Host), "", 1) |
278 | 296 | | protoReq.Raw = []byte(req.Method + " " + reqPath + " " + req.Proto + "\n" + "Host: " + req.URL.Host + "\n" + strings.Trim(rawReqHeaderBuilder.String(), "\n") + "\n\n" + string(rule.Request.Body)) |
279 | 297 | | protoReq.RawHeader = []byte(strings.Trim(rawReqHeaderBuilder.String(), "\n")) |
280 | 298 | | variableMap["request"] = protoReq |
281 | 299 | | |
282 | 300 | | // store the full target url |
283 | | - | variableMap["fulltarget"] = utils.UrlTypeToString(protoResp.Url) |
| 301 | + | variableMap["fulltarget"] = target |
284 | 302 | | |
285 | 303 | | return nil |
286 | 304 | | } |
| skipped 220 lines |