Skip to content

std/http

import "github.com/eugenioenko/goalchemy/std/http"

Package http sends HTTP requests whose bodies stream through std/io: the request body is read from an io.Reader and the response body is an io.ReadCloser, so neither is held in memory whole. It runs on lib/http exchanges, so calls suspend on the host HTTP client.

type Request struct {
Method string
URL string
// Headers alternate names and values, with the rules of lib/http.Do.
Headers []string
// Body is the request body, or nil for none. It is closed after the
// request when it is an io.Closer.
Body io.Reader
// ContentLength is the exact length of Body; zero or less with a Body
// sends it chunked.
ContentLength int64
// Options are lib/http.DoWith transport options, such as a client
// certificate, extra root CAs or a Unix socket.
Options []string
// TimeoutMillis bounds the whole exchange, including reading the
// response body (1..lib/http.MaxExchangeMillis).
TimeoutMillis int64
}

Request is one GET or POST request.

type Response struct {
Status int
Headers []string
Body io.ReadCloser
}

Response is the response to a Request. Body must be closed.

func Do(ctx context.Context, req *Request) (*Response, error)

Do sends req and returns the response once its headers arrive. The response body is read from the server as Body is read; the exchange ends when Body is closed, ctx is canceled or the timeout expires. Redirects are not followed and compression is neither requested nor decoded.