Documentation ¶
Index ¶
- Constants
- Variables
- func ExtractProxyID(ctx context.Context) (string, error)
- func ExtractProxyIDFromGRPC(ctx context.Context) (string, context.Context, error)
- func Forward(l log.Logger, ctx context.Context, c ProxyClient, proxyID string, ...) error
- func InjectProxyID(ctx context.Context, id string) context.Context
- func InjectProxyIDIntoGRPC(ctx context.Context, id string) context.Context
- func RegisterProxyServer(s grpc.ServiceRegistrar, srv ProxyServer)
- type Options
- type Proxy
- type ProxyClient
- type ProxyServer
- type Proxy_RegisterClient
- type Proxy_RegisterServer
- type Request
- type Response
- type UnimplementedProxyServer
- type UnsafeProxyServer
Constants ¶
const ProxyIDHeaderName = "X-Scope-ProxyID"
Variables ¶
var ( ErrNoProxyID = errors.New("no Proxy ID") ErrTooManyProxyIDs = errors.New("multiple Proxy IDs present") )
Errors
var DefaultOrgID string = "none"
var File_httpproxy_proto protoreflect.FileDescriptor
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 ¶
ExtractProxyID gets the proxy ID from the context. For a gRPC context, use ExtractProxyIDFromGRPC instead.
func ExtractProxyIDFromGRPC ¶
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 ¶
InjectProxyID injects the proxy ID into the context.
func InjectProxyIDIntoGRPC ¶
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) }
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_RegisterServer ¶
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) GetRequest ¶
func (*Request) ProtoMessage ¶
func (*Request) ProtoMessage()
func (*Request) ProtoReflect ¶
func (x *Request) ProtoReflect() protoreflect.Message
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) GetResponse ¶
func (*Response) ProtoMessage ¶
func (*Response) ProtoMessage()
func (*Response) ProtoReflect ¶
func (x *Response) ProtoReflect() protoreflect.Message
type UnimplementedProxyServer ¶
type UnimplementedProxyServer struct { }
UnimplementedProxyServer must be embedded to have forward compatible implementations.
func (UnimplementedProxyServer) Register ¶
func (UnimplementedProxyServer) Register(Proxy_RegisterServer) error
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.