Documentation
¶
Overview ¶
Package inprocesshttp serves HTTP client requests straight from an http.Handler in the same process, without a network listener.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewClient ¶
NewClient returns a client that serves every request admit accepts from handler, with the request's Host set to its URL's host, and does not follow redirects. A request admit refuses has its body closed and fails with admit's error, which should name only the URL's scheme, host, and path. A request whose context ends before the handler finishes returns the context's error, so a client Timeout bounds the call; the abandoned handler finishes into its own buffer. A handler panic is re-raised on the caller's goroutine.
It suits short request/response calls such as a token endpoint's: the whole response is buffered and returned only after the handler finishes, so it cannot carry a streamed response, such as an MCP gateway call's; NewStreamingClient does.
func NewStreamingClient ¶
NewStreamingClient returns a client like NewClient's whose responses stream. As net/http's server does, the writer buffers the response: it is sent, and RoundTrip returns, at the handler's first Flush, once 4 KiB is written, or when the handler returns, and each later Flush sends what was written since. Sending only then keeps a handler that finishes its work after writing a reply from racing the caller's next request.
The handler's request context ends with the caller's, or when the caller closes the body; a body read after the caller's context ended fails with its error unless the handler had already finished. The client has no timeout. A handler panic, http.ErrAbortHandler included, drops the response: before anything was sent RoundTrip fails, after that the body fails with io.ErrUnexpectedEOF; any other panic before a response is re-raised on the caller's goroutine, as NewClient does.
Types ¶
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder collects a handler's response in memory. The first status written wins; a handler that writes none gets 200.
func (*Recorder) WriteHeader ¶
WriteHeader records status unless one was already written.