Documentation
¶
Index ¶
- func ContextWithOutgoingHeaders(ctx context.Context, headers http.Header) context.Context
- func ContextWithRosettaID(ctx context.Context) context.Context
- func OutgoingHeadersFromContext(ctx context.Context) http.Header
- func RequestWithRequestID(req *http.Request) *http.Request
- func RosettaIDFromContext(ctx context.Context) string
- func RosettaIDFromRequest(r *http.Request) string
- type HeaderForwarder
- func (hf *HeaderForwarder) GetResponseHeaders(rosettaRequestID string) (http.Header, bool)
- func (hf *HeaderForwarder) HeaderForwarderHandler(next http.Handler) http.Handler
- func (hf *HeaderForwarder) RoundTrip(req *http.Request) (*http.Response, error)
- func (hf *HeaderForwarder) UnaryClientInterceptor(ctx context.Context, method string, req, reply interface{}, ...) error
- func (hf *HeaderForwarder) WithTransport(transport http.RoundTripper) *HeaderForwarder
- type ResponseWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithOutgoingHeaders ¶ added in v0.8.7
func OutgoingHeadersFromContext ¶ added in v0.8.7
func RequestWithRequestID ¶ added in v0.8.7
RequestWithRequestID adds a unique ID to the request context. A new request is returned that contains the new context
func RosettaIDFromContext ¶
func RosettaIDFromRequest ¶
Types ¶
type HeaderForwarder ¶
type HeaderForwarder struct {
// contains filtered or unexported fields
}
HeaderExtractingTransport is a utility to help a rosetta server forward headers to and from native node requests. It implements several interfaces to achieve that:
- http.RoundTripper: this can be used to create an http Client that will automatically save headers if necessary
- func(http.Handler) http.Handler: this can be used to wrap an http.Handler to set headers on the response
the headers can be requested later.
TODO: this should expire entries after a certain amount of time
func NewHeaderForwarder ¶
func NewHeaderForwarder( interestingHeaders []string, transport http.RoundTripper, ) (*HeaderForwarder, error)
func (*HeaderForwarder) GetResponseHeaders ¶ added in v0.8.9
func (hf *HeaderForwarder) GetResponseHeaders(rosettaRequestID string) (http.Header, bool)
GetResponseHeaders returns any headers that should be returned to a rosetta response. These consist of native node response headers/metadata that were remembered for a request ID.
func (*HeaderForwarder) HeaderForwarderHandler ¶
func (hf *HeaderForwarder) HeaderForwarderHandler(next http.Handler) http.Handler
HeaderForwarderHandler will allow the next handler to serve the request, and then checks if there are any native node response headers recorded for the request. If there are, it will set those headers on the response
func (*HeaderForwarder) RoundTrip ¶
RoundTrip implements http.RoundTripper and will be used to construct an http Client which saves the native node response headers if necessary.
func (*HeaderForwarder) UnaryClientInterceptor ¶ added in v0.8.7
func (hf *HeaderForwarder) UnaryClientInterceptor( ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption, ) error
func (*HeaderForwarder) WithTransport ¶ added in v0.8.7
func (hf *HeaderForwarder) WithTransport(transport http.RoundTripper) *HeaderForwarder
type ResponseWriter ¶
type ResponseWriter struct {
RosettaRequestID string
GetAdditionalHeaders func(string) (http.Header, bool)
// contains filtered or unexported fields
}
ResponseWriter is a wrapper around a http.ResponseWriter that allows us to set headers just before the WriteHeader function is called. These headers will be extracted from native node responses, and set on the rosetta response.
func NewResponseWriter ¶
func NewResponseWriter( writer http.ResponseWriter, rosettaRequestID string, getAdditionalHeaders func(string) (http.Header, bool), ) *ResponseWriter
func (*ResponseWriter) AddExtractedHeaders ¶
func (hfrw *ResponseWriter) AddExtractedHeaders()
func (*ResponseWriter) Header ¶
func (hfrw *ResponseWriter) Header() http.Header
Header passes through to the underlying ResponseWriter instance
func (*ResponseWriter) Write ¶
func (hfrw *ResponseWriter) Write(b []byte) (int, error)
Write passes through to the underlying ResponseWriter instance
func (*ResponseWriter) WriteHeader ¶
func (hfrw *ResponseWriter) WriteHeader(statusCode int)
WriteHeader will add any final extracted headers, and then pass through to the underlying ResponseWriter instance