httptunnel

package
v0.28.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func NoRedirect(*http.Request, []*http.Request) error

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 NewBody

func NewBody() *Body

NewBody returns a Body whose first pipe is ready to be sent.

func (*Body) CloseWithError

func (b *Body) CloseWithError(err error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL