Do performs the HTTP request req using the pipe's configured HTTP client, as set by [Pipe.WithHTTPClient], or [http.DefaultClient] otherwise. The response body is streamed concurrently to the pipe's output. If the response status is anything other than HTTP 200-299, the pipe's error status is set.
(req *http.Request)
| 327 | // response body is streamed concurrently to the pipe's output. If the response |
| 328 | // status is anything other than HTTP 200-299, the pipe's error status is set. |
| 329 | func (p *Pipe) Do(req *http.Request) *Pipe { |
| 330 | return p.Filter(func(r io.Reader, w io.Writer) error { |
| 331 | resp, err := p.httpClient.Do(req) |
| 332 | if err != nil { |
| 333 | return err |
| 334 | } |
| 335 | defer resp.Body.Close() |
| 336 | _, err = io.Copy(w, resp.Body) |
| 337 | if err != nil { |
| 338 | return err |
| 339 | } |
| 340 | // Any HTTP 2xx status code is considered okay |
| 341 | if resp.StatusCode/100 != 2 { |
| 342 | return fmt.Errorf("unexpected HTTP response status: %s", resp.Status) |
| 343 | } |
| 344 | return nil |
| 345 | }) |
| 346 | } |
| 347 | |
| 348 | // EachLine calls the function process on each line of input, passing it the |
| 349 | // line as a string, and a [*strings.Builder] to write its output to. |