Documentation
¶
Overview ¶
Package httptunnel provides the pieces shared by the HTTP tunnel dialers and connectors: a replayable tunnel body and the redirect policy a tunnel client must use.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NoRedirect ¶
NoRedirect makes a tunnel client return a redirect response instead of following it. A tunnel request carries its data in the body, and net/http drops the body when it follows 301/302/303 and does not follow 307/308 without Request.GetBody. Either way the redirected request has no body, so following it would hand back a connection whose write side is never read. The response is returned to the caller as a failed attempt instead, which the handler can retry.
Types ¶
type Body ¶
type Body struct {
// contains filtered or unexported fields
}
Body carries the client-to-server half of a tunnel as the body of an HTTP request (CONNECT, or GET for a path-based endpoint).
The body has no content until the request is sent, so every attempt needs a new pipe. When the transport retries the request on another connection (the server sent GOAWAY, or the connection broke, before the stream was opened), it resends the same *http.Request. Without Request.GetBody the retry reuses the pipe that the previous attempt already closed (golang/go#82177), and the tunnel is left with a dead write side.
GetBody hands out a fresh pipe per attempt and Writer returns the writer of the pipe handed out last. That is the pipe the transport sends, because GetBody runs synchronously on the goroutine that calls Client.Do, before the next attempt starts. Nothing is written before the dial returns, so a fresh pipe is an exact replacement for the closed one.
func (*Body) CloseWithError ¶
CloseWithError closes both ends of the current pipe with err: the transport is left with a failed body read, and writes to the tunnel fail with err.
func (*Body) GetBody ¶
func (b *Body) GetBody() (io.ReadCloser, error)
GetBody implements http.Request.GetBody.
func (*Body) Reader ¶
func (b *Body) Reader() io.ReadCloser
Reader returns the body for the first attempt.
func (*Body) Writer ¶
func (b *Body) Writer() io.WriteCloser
Writer returns the write side of the tunnel: the writer of the pipe handed out last, which is the pipe the transport reads.