httptun

package
v0.0.0-...-6a3c429 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const ProxyIDHeaderName = "X-Scope-ProxyID"

Variables

View Source
var (
	ErrNoProxyID       = errors.New("no Proxy ID")
	ErrTooManyProxyIDs = errors.New("multiple Proxy IDs present")
)

Errors

View Source
var DefaultOrgID string = "none"
View Source
var File_httpproxy_proto protoreflect.FileDescriptor
View Source
var Proxy_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "httptun.Proxy",
	HandlerType: (*ProxyServer)(nil),
	Methods:     []grpc.MethodDesc{},
	Streams: []grpc.StreamDesc{
		{
			StreamName:    "Register",
			Handler:       _Proxy_Register_Handler,
			ServerStreams: true,
			ClientStreams: true,
		},
	},
	Metadata: "httpproxy.proto",
}

Proxy_ServiceDesc is the grpc.ServiceDesc for Proxy service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

Functions

func ExtractProxyID

func ExtractProxyID(ctx context.Context) (string, error)

ExtractProxyID gets the proxy ID from the context. For a gRPC context, use ExtractProxyIDFromGRPC instead.

func ExtractProxyIDFromGRPC

func ExtractProxyIDFromGRPC(ctx context.Context) (string, context.Context, error)

ExtractProxyIDFromGRPC extracts the proxy ID from a gRPC context. The returned context has the proxy ID injected and can be extracted with ExtractProxyID.

func Forward

func Forward(l log.Logger, ctx context.Context, c ProxyClient, proxyID string, h http.Handler) error

Forward will connect to the ProxyClient c with the provided context and proxy ID. The handler h will be invoked for every proxied request received.

To stop forwarding, cancel the provided context.

func InjectProxyID

func InjectProxyID(ctx context.Context, id string) context.Context

InjectProxyID injects the proxy ID into the context.

func InjectProxyIDIntoGRPC

func InjectProxyIDIntoGRPC(ctx context.Context, id string) context.Context

InjectProxyIDIntoGRPC injects a proxy ID into a gRPC context.

func RegisterProxyServer

func RegisterProxyServer(s grpc.ServiceRegistrar, srv ProxyServer)

Types

type Options

type Options struct {
	// Multitenant enables multi-tenancy. When enabled, an X-Scope-OrgID header
	// must be present for all requests to indicate the tenant.
	Multitenant bool
}

Options controls the proxy.

type Proxy

type Proxy interface {
	ProxyServer

	// ListPeers lists the ID for all proxy peers.
	ListPeers(ctx context.Context) ([]string, error)

	// HandlerFor returns an http.Handler for a given proxyID. Requests
	// will be proxied to the connected peer with that proxyID.
	HandlerFor(ctx context.Context, proxyID string) (http.Handler, error)
}

func New

func New(opts Options) Proxy

New creates a new Proxy.

type ProxyClient

type ProxyClient interface {
	// Register registers the client as a proxy target. The clent MUST provide
	// an X-Scope-ProxyID header when calling this method that uniquely identifies
	// themselves amongst other connected peers. Once connected, the client
	// should respond to any request provided by the server.
	Register(ctx context.Context, opts ...grpc.CallOption) (Proxy_RegisterClient, error)
}

ProxyClient is the client API for Proxy service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

func NewProxyClient

func NewProxyClient(cc grpc.ClientConnInterface) ProxyClient

type ProxyServer

type ProxyServer interface {
	// Register registers the client as a proxy target. The clent MUST provide
	// an X-Scope-ProxyID header when calling this method that uniquely identifies
	// themselves amongst other connected peers. Once connected, the client
	// should respond to any request provided by the server.
	Register(Proxy_RegisterServer) error
	// contains filtered or unexported methods
}

ProxyServer is the server API for Proxy service. All implementations must embed UnimplementedProxyServer for forward compatibility

type Proxy_RegisterClient

type Proxy_RegisterClient interface {
	Send(*Response) error
	Recv() (*Request, error)
	grpc.ClientStream
}

type Proxy_RegisterServer

type Proxy_RegisterServer interface {
	Send(*Request) error
	Recv() (*Response, error)
	grpc.ServerStream
}

type Request

type Request struct {

	// ID of the request. Generated responses must have a matchnig ID.
	// The peer will ensure that no two concurrent requests have the same ID.
	Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
	// Encoded HTTP request.
	Request []byte `protobuf:"bytes,2,opt,name=request,proto3" json:"request,omitempty"`
	// contains filtered or unexported fields
}

func (*Request) Descriptor deprecated

func (*Request) Descriptor() ([]byte, []int)

Deprecated: Use Request.ProtoReflect.Descriptor instead.

func (*Request) GetId

func (x *Request) GetId() int64

func (*Request) GetRequest

func (x *Request) GetRequest() []byte

func (*Request) ProtoMessage

func (*Request) ProtoMessage()

func (*Request) ProtoReflect

func (x *Request) ProtoReflect() protoreflect.Message

func (*Request) Reset

func (x *Request) Reset()

func (*Request) String

func (x *Request) String() string

type Response

type Response struct {

	// ID of the response, matching an ID of an incoming request.
	Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
	// Encoded HTTP response.
	Response []byte `protobuf:"bytes,2,opt,name=response,proto3" json:"response,omitempty"`
	// contains filtered or unexported fields
}

func (*Response) Descriptor deprecated

func (*Response) Descriptor() ([]byte, []int)

Deprecated: Use Response.ProtoReflect.Descriptor instead.

func (*Response) GetId

func (x *Response) GetId() int64

func (*Response) GetResponse

func (x *Response) GetResponse() []byte

func (*Response) ProtoMessage

func (*Response) ProtoMessage()

func (*Response) ProtoReflect

func (x *Response) ProtoReflect() protoreflect.Message

func (*Response) Reset

func (x *Response) Reset()

func (*Response) String

func (x *Response) String() string

type UnimplementedProxyServer

type UnimplementedProxyServer struct {
}

UnimplementedProxyServer must be embedded to have forward compatible implementations.

func (UnimplementedProxyServer) Register

type UnsafeProxyServer

type UnsafeProxyServer interface {
	// contains filtered or unexported methods
}

UnsafeProxyServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to ProxyServer will result in compilation errors.

Jump to

Keyboard shortcuts

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