(spec ReplaySpec)
| 1281 | } |
| 1282 | |
| 1283 | func executeReplay(spec ReplaySpec) (ResponseInfo, error) { |
| 1284 | switch spec.kind { |
| 1285 | case "http": |
| 1286 | var proxyURL *url.URL |
| 1287 | if spec.proxy != "" { |
| 1288 | parsed, err := url.Parse(spec.proxy) |
| 1289 | if err != nil { |
| 1290 | return ResponseInfo{}, err |
| 1291 | } |
| 1292 | proxyURL = parsed |
| 1293 | } |
| 1294 | return requestWithRetryBody(spec.method, spec.uri, spec.headers, spec.body, proxyURL, false, spec.timeout, spec.redirect) |
| 1295 | case "raw": |
| 1296 | return rawRequest(spec.method, spec.uri, spec.requestTarget, spec.headers, spec.body, spec.timeout) |
| 1297 | case "curl": |
| 1298 | ctx, cancel := context.WithTimeout(context.Background(), time.Duration(spec.timeout)*time.Millisecond) |
| 1299 | defer cancel() |
| 1300 | cmd := exec.CommandContext(ctx, "curl", spec.curlArgs...) |
| 1301 | out, err := cmd.Output() |
| 1302 | if err != nil { |
| 1303 | return ResponseInfo{}, err |
| 1304 | } |
| 1305 | res := parseCurlOutput(string(out), "curl-replay") |
| 1306 | return ResponseInfo{ |
| 1307 | statusCode: res.statusCode, |
| 1308 | contentLength: res.contentLength, |
| 1309 | bodyHash: res.bodyHash, |
| 1310 | location: res.location, |
| 1311 | contentType: res.contentType, |
| 1312 | server: res.server, |
| 1313 | }, nil |
| 1314 | default: |
| 1315 | return ResponseInfo{}, fmt.Errorf("unsupported replay kind %q", spec.kind) |
| 1316 | } |
| 1317 | } |
| 1318 | |
| 1319 | func wrapText(text string, width int) []string { |
| 1320 | if len(text) <= width { |
no test coverage detected