httpproxy

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 19 Imported by: ? 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GzipMiddleware

func GzipMiddleware(next http.Handler) http.Handler

GzipMiddleware compresses HTTP responses and decompresses requests.

It handles both request decompression (Content-Encoding: gzip) and response compression (Accept-Encoding: gzip). A compressed request body is decompressed only once the handler reads it.

Requests without compression are handled normally for backward compatibility.

Types

type Admission added in v0.4.0

type Admission struct {
	// Metadata is what the call carries to its backend, in place of any
	// request header.
	Metadata metadata.MD
	// MaxBodySize bounds the body of the call.
	MaxBodySize int64
	// Release ends the admission once the call is done, however it ended.
	Release func()
}

Admission is what an HTTP call is let in with before its body is read.

type Admitter added in v0.4.0

type Admitter func(r *http.Request, fullMethodName string) (Admission, error)

Admitter lets an HTTP call in before its body is read, or refuses it with a status error.

type Backend added in v0.4.0

type Backend interface {
	GetConnection(ctx context.Context, fullMethodName string) (context.Context, *grpc.ClientConn, error)
}

Backend returns the gRPC connection a call goes over and the context the call runs under, derived from the given one.

type BackendRegistry

type BackendRegistry interface {
	HasBackend(service string) bool
}

BackendRegistry tells the HTTP proxy which services are registered.

A handler asks it before it reads the request body, so a call to an unregistered service costs no read, and asks again once the body is read.

type Option

type Option func(*handlerOptions)

Option configures the HTTPHandler constructor.

func WithLog

func WithLog(log *zap.Logger) Option

WithLog sets the logger for the HTTP handler.

func WithTrustedOrigins added in v0.3.0

func WithTrustedOrigins(origins []string) Option

WithTrustedOrigins sets the origins whose browser pages may read the handler's responses cross-origin.

A request from any other origin gets no CORS headers, so the browser withholds the response from the calling page.

type TransparentWebGRPCProxy

type TransparentWebGRPCProxy struct {
	// contains filtered or unexported fields
}

TransparentWebGRPCProxy is an HTTP handler that translates HTTP requests with binary protobuf payloads to gRPC calls.

func NewHTTPHandler

func NewHTTPHandler(backend Backend, registry BackendRegistry, admitter Admitter, options ...Option) *TransparentWebGRPCProxy

NewHTTPHandler creates a new HTTPHandler that sends every call of a service the registry knows and the admitter lets in to the backend.

func (*TransparentWebGRPCProxy) ServeHTTP

ServeHTTP handles HTTP requests.

Jump to

Keyboard shortcuts

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