MCPcopy
hub / github.com/bitfield/script / Do

Method Do

script.go:329–346  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
329func (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.

Callers 6

GetMethod · 0.95
PostMethod · 0.95
DoFunction · 0.80
LastMethod · 0.80
ExamplePipe_DoFunction · 0.80

Calls 2

FilterMethod · 0.95
CloseMethod · 0.45

Tested by 2

ExamplePipe_DoFunction · 0.64