middlewares

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2020 License: MPL-2.0 Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoggingMiddleware

func LoggingMiddleware(next http.Handler) http.Handler

LoggingMiddleware prints the request URI.

func NewDumpMiddleware

func NewDumpMiddleware(dumpAction func(*RoundtripDump)) func(next http.Handler) http.Handler

NewDumpMiddleware creates a new DumpMiddleware to call a function with the RoundtripDump objects.

func NewDumpToLogMiddleware

func NewDumpToLogMiddleware() func(next http.Handler) http.Handler

NewDumpToLogMiddleware creates a new DumpMiddleware to log the RoundtripDump objects as serialised json string.

func NewRequestHeaderWriteMiddlwware

func NewRequestHeaderWriteMiddlwware(headers map[string]string) func(next http.Handler) http.Handler

NewRequestHeaderWriteMiddlwware creates a middleware to rewrite HTTP headers of requests.

func NewResponseHeaderWriteMiddlwware

func NewResponseHeaderWriteMiddlwware(headers map[string]string) func(next http.Handler) http.Handler

NewResponseHeaderWriteMiddlwware creates a middleware to rewrite HTTP headers of responses.

Types

type RequestDump

type RequestDump struct {
	Method   string              `json:"method"`
	Target   string              `json:"target"`
	Protocol string              `json:"protocol"`
	Headers  map[string][]string `json:"headers"`
	Body     string              `json:"body"`
}

RequestDump - A RequestDump object represents an HTTP request. The HTTP method is stored as a string. The HTTP target url is stored as a string. The HTTP protocal, e.g. HTTP/HTTPS, is stored as a string. The HTTP headers are stored in a string-string map. The HTTP body is stored as a string.

type ResponseDump

type ResponseDump struct {
	Headers    map[string]string `json:"headers"`
	Body       string            `json:"body"`
	StatusCode int               `json:"status_code"`
}

ResponseDump - A ResponseDump object represents an HTTP response. The HTTP headers are stored in a string-string map. The HTTP body is stored as a string. The HTTP status code is stored as an integer.

type ResponseSnifferingWriter

type ResponseSnifferingWriter struct {
	http.ResponseWriter
	MultiWriter io.Writer
	BytesBuffer *bytes.Buffer
	Status      int
}

ResponseSnifferingWriter overrides the logic of http.ResponseWriter to dump the full roundtrips of HTTP calls.

func NewResponseSnifferingWriter

func NewResponseSnifferingWriter(realWriter http.ResponseWriter) ResponseSnifferingWriter

NewResponseSnifferingWriter initiates a ResponseSnifferingWriter object.

func (*ResponseSnifferingWriter) Header

func (w *ResponseSnifferingWriter) Header() http.Header

Header overrides the logic of http.ResponseWriter.Header()

func (*ResponseSnifferingWriter) Write

func (w *ResponseSnifferingWriter) Write(b []byte) (n int, err error)

Write overrides the logic of http.ResponseWriter.Write()

func (*ResponseSnifferingWriter) WriteHeader

func (w *ResponseSnifferingWriter) WriteHeader(status int)

WriteHeader overrides the logic of http.ResponseWriter.WriteHeader()

type RoundtripDump

type RoundtripDump struct {
	Timestamp time.Time    `json:"timestamp"`
	Request   RequestDump  `json:"request"`
	Response  ResponseDump `json:"response"`
}

RoundtripDump - A RoundtripDump object represents a full roundtrip of an HTTP call.

Jump to

Keyboard shortcuts

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