### Full Example: Client-Side Logging Source: https://pkg.go.dev/github.com/henvic/httpretty A complete example demonstrating how to configure httpretty logger and use it with the default HTTP client to log requests to google.com. ```go package main import ( "fmt" "net/http" "os" "github.com/henvic/httpretty" ) func main() { logger := &httpretty.Logger{ Time: true, TLS: true, RequestHeader: true, RequestBody: true, ResponseHeader: true, ResponseBody: true, Colors: true, Formatters: []httpretty.Formatter{&httpretty.JSONFormatter{}}, } http.DefaultClient.Transport = logger.RoundTripper(http.DefaultClient.Transport) // tip: you can use it on any *http.Client if _, err := http.Get("https://www.google.com/"); err != nil { fmt.Fprintf(os.Stderr, "%+v\n", err) os.Exit(1) } } ``` -------------------------------- ### Basic Server-Side Logging Setup Source: https://pkg.go.dev/github.com/henvic/httpretty A minimal setup for server-side logging using httpretty. Note that server logs may not include response headers set by the server itself. ```go logger := &httpretty.Logger{ Time: true, TLS: true, RequestHeader: true, RequestBody: true, ResponseHeader: true, ResponseBody: true, } logger.Middleware(handler) ``` -------------------------------- ### Configure httpretty Logger Source: https://pkg.go.dev/github.com/henvic/httpretty Set up a logger with various options for detailed HTTP request logging, including timestamps, TLS info, headers, and request/response bodies. Colors can be enabled for better readability. A JSON formatter is included. ```go logger := &httpretty.Logger{ Time: true, TLS: true, RequestHeader: true, RequestBody: true, ResponseHeader: true, ResponseBody: true, Colors: true, // erase line if you don't like colors Formatters: []httpretty.Formatter{&httpretty.JSONFormatter{}}, } ``` -------------------------------- ### Use httpretty on Client-Side Source: https://pkg.go.dev/github.com/henvic/httpretty Integrate httpretty with a Go `http.Client` by setting its `Transport`. This allows logging of all outgoing HTTP requests made by that client. It's recommended to use a custom client to manage timeouts. ```go client := &http.Client{ Transport: logger.RoundTripper(http.DefaultTransport), } // from now on, you can use client.Do, client.Get, etc. to create requests. ``` ```go http.DefaultClient.Transport = logger.RoundTripper(http.DefaultClient.Transport) ``` ```go if _, err := http.Get("https://www.google.com/"); err != nil { fmt.Fprintf(os.Stderr, "%+v\n", err) os.Exit(1) } ``` -------------------------------- ### Use httpretty on Server-Side Source: https://pkg.go.dev/github.com/henvic/httpretty Apply httpretty logging to a server-side HTTP handler using the `Middleware` function. This logs incoming requests to the specified handler. ```go logger.Middleware(mux) ``` -------------------------------- ### Configure Logger Flushing Strategy Source: https://pkg.go.dev/github.com/henvic/httpretty Flusher defines how the logger prints requests. Choose between immediate printing (NoBuffer), printing when ready (OnReady), or printing at the end (OnEnd). ```go type Flusher int ``` ```go const ( // NoBuffer strategy prints anything immediately, without buffering. // It has the issue of mingling concurrent requests in unpredictable ways. NoBuffer Flusher = iota // OnReady buffers and prints each step of the request or response (header, body) whenever they are ready. // It reduces mingling caused by mingling but does not give any ordering guarantee, so responses can still be out of order. OnReady // OnEnd buffers the whole request and flushes it once, in the end. OnEnd ) ``` -------------------------------- ### Define HTTP Body Formatting Interface Source: https://pkg.go.dev/github.com/henvic/httpretty Formatter allows custom formatting of request/response bodies. The Match method checks the media type, and Format performs the actual formatting. If Format returns an error, the content is printed verbatim. ```go type Formatter interface { Match(mediatype string) bool Format(w io.Writer, src []byte) error } ``` -------------------------------- ### Create Logging RoundTripper Source: https://pkg.go.dev/github.com/henvic/httpretty Returns a http.RoundTripper that utilizes the logger. Use this to wrap existing RoundTrippers for logging client-side requests. ```go func (l *Logger) RoundTripper(rt http.RoundTripper) http.RoundTripper ``` -------------------------------- ### Print HTTP Response Source: https://pkg.go.dev/github.com/henvic/httpretty Prints an HTTP response. Use this method to log response details. ```go func (l *Logger) PrintResponse(resp *http.Response) ``` -------------------------------- ### Print HTTP Request Source: https://pkg.go.dev/github.com/henvic/httpretty Prints a request, overriding any 'WithHide' settings. This method does not log TLS connection details or request duration. ```go func (l *Logger) PrintRequest(req *http.Request) ``` -------------------------------- ### Implement JSON Formatting Source: https://pkg.go.dev/github.com/henvic/httpretty Format JSON content using the JSONFormatter. This method is part of the Formatter interface. ```go func (j *JSONFormatter) Format(w io.Writer, src []byte) error ``` -------------------------------- ### Logger Middleware for HTTP Server Source: https://pkg.go.dev/github.com/henvic/httpretty Provides middleware to log incoming HTTP requests to a server. Wrap your http.Handler with this method to enable logging. ```go func (l *Logger) Middleware(next http.Handler) http.Handler ``` -------------------------------- ### Background Hi-Intensity text colors Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/color Constants for background Hi-Intensity text colors. ```go const ( BgHiBlack Attribute = iota + 100 BgHiRed BgHiGreen BgHiYellow BgHiBlue BgHiMagenta BgHiCyan BgHiWhite ) ``` -------------------------------- ### Foreground Hi-Intensity text colors Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/color Constants for foreground Hi-Intensity text colors. ```go const ( FgHiBlack Attribute = iota + 90 FgHiRed FgHiGreen FgHiYellow FgHiBlue FgHiMagenta FgHiCyan FgHiWhite ) ``` -------------------------------- ### Logger.SetOutput Source: https://pkg.go.dev/github.com/henvic/httpretty SetOutput sets the output destination for the logger. ```APIDOC ## Logger.SetOutput ### Description Sets the output destination for the logger. ### Method `SetOutput` ### Parameters - `w` (io.Writer) - The writer to set as the output destination. ``` -------------------------------- ### Logger.Middleware Source: https://pkg.go.dev/github.com/henvic/httpretty Middleware for logging incoming requests to a HTTP server. ```APIDOC ## Logger.Middleware ### Description Middleware for logging incoming requests to a HTTP server. ### Method `Middleware` ### Parameters - `next` (*http.Handler) - The next http.Handler in the chain. ### Returns - `http.Handler` - The handler with logging middleware applied. ``` -------------------------------- ### Base attributes Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/color Constants for base text attributes like Reset, Bold, Italic, Underline, Blink, ReverseVideo, Concealed, and CrossedOut. ```go const ( Reset Attribute = iota Bold Faint Italic Underline BlinkSlow BlinkRapid ReverseVideo Concealed CrossedOut ) ``` -------------------------------- ### Background text colors Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/color Constants for background text colors, including standard and Hi-Intensity shades. ```go const ( BgBlack Attribute = iota + 40 BgRed BgGreen BgYellow BgBlue BgMagenta BgCyan BgWhite ) ``` -------------------------------- ### Foreground text colors Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/color Constants for foreground text colors, including standard and Hi-Intensity shades. ```go const ( FgBlack Attribute = iota + 30 FgRed FgGreen FgYellow FgBlue FgMagenta FgCyan FgWhite ) ``` -------------------------------- ### Set Output Destination for Logger Source: https://pkg.go.dev/github.com/henvic/httpretty Sets the output destination (an io.Writer) for the logger. By default, logs go to os.Stderr. ```go func (l *Logger) SetOutput(w io.Writer) ``` -------------------------------- ### Format text for terminal Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/color Format text for terminal output by passing attributes and values. Supports arbitrary number of Attribute or []Attribute followed by strings or other convertible types. ```go func Format(s ...interface{}) string ``` -------------------------------- ### Define Request Filtering Logic Source: https://pkg.go.dev/github.com/henvic/httpretty Filter allows skipping entire requests. You can return a non-null error to log it. ```go type Filter func(req *http.Request) (skip bool, err error) ``` -------------------------------- ### Format String Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/color Formats a string with specified attributes and content for terminal output. It can accept a variable number of attributes and values. ```APIDOC ## func Format ### Description Format text for terminal. You can pass an arbitrary number of Attribute or []Attribute followed by any other values, that can either be a string or something else (that is converted to string using fmt.Sprint). ### Signature ```go func Format(s ...interface{}) string ``` ``` -------------------------------- ### Logger.PrintResponse Source: https://pkg.go.dev/github.com/henvic/httpretty PrintResponse prints a response. ```APIDOC ## Logger.PrintResponse ### Description Prints a response. ### Method `PrintResponse` ### Parameters - `resp` (*http.Response) - The HTTP response to print. ``` -------------------------------- ### Skip Specific Headers from Logging Source: https://pkg.go.dev/github.com/henvic/httpretty Allows specifying a list of header names to exclude from logging. This method is safe for concurrent use. ```go func (l *Logger) SkipHeader(headers []string) ``` -------------------------------- ### Set Request Filter for Logger Source: https://pkg.go.dev/github.com/henvic/httpretty Allows setting a function to conditionally skip logging entire requests. Pass nil to remove any existing filter. This method is safe for concurrent use. ```go func (l *Logger) SetFilter(f Filter) ``` -------------------------------- ### Filter Requests with a Custom Function Source: https://pkg.go.dev/github.com/henvic/httpretty Implement a custom filter function to conditionally skip requests based on criteria like HTTP method or URL path. Set this filter using `logger.SetFilter`. ```go type Filter func(req *http.Request) (skip bool, err error) ``` ```go logger.SetFilter(func filteredURIs(req *http.Request) (bool, error) { if req.Method != http.MethodGet { return true, nil } if path := req.URL.Path; path == "/debug" || strings.HasPrefix(path, "/debug/") { return true, nil } return false }) ``` -------------------------------- ### Set Flusher Strategy for Logger Source: https://pkg.go.dev/github.com/henvic/httpretty Sets the flush strategy for the logger. This controls how and when log output is flushed. ```go func (l *Logger) SetFlusher(f Flusher) ``` -------------------------------- ### Set Body Filter for Logger Source: https://pkg.go.dev/github.com/henvic/httpretty Allows setting a function to conditionally skip printing the request or response body. Pass nil to remove any existing body filter. This method is safe for concurrent use. ```go func (l *Logger) SetBodyFilter(f BodyFilter) ``` -------------------------------- ### Match JSON Media Type Source: https://pkg.go.dev/github.com/henvic/httpretty Match determines if the JSONFormatter should handle the given media type. This method is part of the Formatter interface. ```go func (j *JSONFormatter) Match(mediatype string) bool ``` -------------------------------- ### Formatter Source: https://pkg.go.dev/github.com/henvic/httpretty Formatter can be used to format body. If the Format function returns an error, the content is printed in verbatim after a warning. Match receives a media type from the Content-Type field. The body is formatted if it returns true. ```APIDOC ## Formatter ### Description Formatter can be used to format body. If the Format function returns an error, the content is printed in verbatim after a warning. Match receives a media type from the Content-Type field. The body is formatted if it returns true. ### Interface Definition ```go interface Formatter { Match(mediatype string) bool Format(w io.Writer, src []byte) error } ``` ``` -------------------------------- ### Sanitize HTTP Headers Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/header Sanitize applies a given set of sanitizers to an http.Header. It iterates through the headers and applies the corresponding sanitizer function if one is defined for the header key. Consult MDN for header syntax. ```go func Sanitize(sanitizers map[string]SanitizeHeaderFunc, headers http.Header) http.Header ``` -------------------------------- ### Logger.SetFilter Source: https://pkg.go.dev/github.com/henvic/httpretty SetFilter allows you to set a function to skip requests. Pass nil to remove the filter. This method is concurrency safe. ```APIDOC ## Logger.SetFilter ### Description Allows you to set a function to skip requests. Pass nil to remove the filter. This method is concurrency safe. ### Method `SetFilter` ### Parameters - `f` (Filter) - The function to use for filtering requests. ``` -------------------------------- ### Attribute type definition Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/color Defines a single SGR (Select Graphic Rendition) code for terminal styling. Used with Format function. ```go type Attribute int ``` -------------------------------- ### Filter Requests with httpretty.WithHide Source: https://pkg.go.dev/github.com/henvic/httpretty Prevent specific requests from being logged by adding a context value using `httpretty.WithHide` before the request is processed by the logger's `RoundTripper`. ```go req = req.WithContext(httpretty.WithHide(ctx)) ``` -------------------------------- ### JSONFormatter Source: https://pkg.go.dev/github.com/henvic/httpretty JSONFormatter helps you read unreadable JSON documents. github.com/tidwall/pretty could be used to add colors to it. However, it would add an external dependency. If you want, you can define your own formatter using it or anything else. See Formatter. ```APIDOC ## JSONFormatter ### Description JSONFormatter helps you read unreadable JSON documents. github.com/tidwall/pretty could be used to add colors to it. However, it would add an external dependency. If you want, you can define your own formatter using it or anything else. See Formatter. ### Type Definition ```go type JSONFormatter struct{} ``` ### Methods #### Format Format JSON content. ```go func (j *JSONFormatter) Format(w io.Writer, src []byte) error ``` #### Match Match JSON media type. ```go func (j *JSONFormatter) Match(mediatype string) bool ``` ``` -------------------------------- ### Strip attributes from input Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/color Strip ANSI attributes from input arguments and return the raw, unformatted text. Useful for cleaning output. ```go func StripAttributes(s ...interface{}) (raw string) ``` -------------------------------- ### Filter Source: https://pkg.go.dev/github.com/henvic/httpretty Filter allows you to skip requests. If an error happens and you want to log it, you can pass a not-null error value. ```APIDOC ## Filter ### Description Filter allows you to skip requests. If an error happens and you want to log it, you can pass a not-null error value. ### Type Definition ```go type Filter func(req *http.Request) (skip bool, err error) ``` ``` -------------------------------- ### Protect Request from Exposure Source: https://pkg.go.dev/github.com/henvic/httpretty Use WithHide to prevent a request from being exposed in logs. This function returns a context that signals the request should be hidden. ```go func WithHide(ctx context.Context) context.Context ``` -------------------------------- ### WithHide Source: https://pkg.go.dev/github.com/henvic/httpretty WithHide can be used to protect a request from being exposed. ```APIDOC ## WithHide ### Description WithHide can be used to protect a request from being exposed. ### Function Signature ```go func WithHide(ctx context.Context) context.Context ``` ``` -------------------------------- ### Strip Attributes Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/color Strips all ANSI attributes from the input arguments and returns the plain, unformatted text. ```APIDOC ## func StripAttributes ### Description StripAttributes from input arguments and return unformatted text. ### Signature ```go func StripAttributes(s ...interface{}) (raw string) ``` ``` -------------------------------- ### Logger.SkipHeader Source: https://pkg.go.dev/github.com/henvic/httpretty SkipHeader allows you to skip printing specific headers. This method is concurrency safe. ```APIDOC ## Logger.SkipHeader ### Description Allows you to skip printing specific headers. This method is concurrency safe. ### Method `SkipHeader` ### Parameters - `headers` ([]string) - A slice of header names to skip. ``` -------------------------------- ### Define HTTP Body Filtering Logic Source: https://pkg.go.dev/github.com/henvic/httpretty BodyFilter allows skipping the printing of an HTTP body based on its headers. It's called even when no body is present on HTTP servers. ```go type BodyFilter func(h http.Header) (skip bool, err error) ``` -------------------------------- ### Logger Source: https://pkg.go.dev/github.com/henvic/httpretty Logger provides middleware for HTTP handlers and round trippers to log requests and responses. ```APIDOC ## Logger ### Description Logger provides middleware for HTTP handlers and round trippers to log requests and responses. ### Methods #### Middleware Returns an http.Handler middleware that logs requests and responses. ```go func (l *Logger) Middleware(next http.Handler) http.Handler ``` #### PrintRequest Prints the details of an HTTP request. ```go func (l *Logger) PrintRequest(req *http.Request) ``` #### PrintResponse Prints the details of an HTTP response. ```go func (l *Logger) PrintResponse(resp *http.Response) ``` #### RoundTripper Wraps an http.RoundTripper to log requests and responses. ```go func (l *Logger) RoundTripper(rt http.RoundTripper) http.RoundTripper ``` #### SetBodyFilter Sets a BodyFilter to control which request/response bodies are logged. ```go func (l *Logger) SetBodyFilter(f BodyFilter) ``` #### SetFilter Sets a Filter to control which requests are logged. ```go func (l *Logger) SetFilter(f Filter) ``` #### SetFlusher Sets the Flusher strategy for logging. ```go func (l *Logger) SetFlusher(f Flusher) ``` #### SetOutput Sets the output writer for the logger. ```go func (l *Logger) SetOutput(w io.Writer) ``` #### SkipHeader Specifies headers to skip when logging. ```go func (l *Logger) SkipHeader(headers []string) ``` ``` -------------------------------- ### Logger.PrintRequest Source: https://pkg.go.dev/github.com/henvic/httpretty PrintRequest prints a request, even when WithHide is used to hide it. It doesn't log TLS connection details or request duration. ```APIDOC ## Logger.PrintRequest ### Description Prints a request, even when WithHide is used to hide it. It doesn't log TLS connection details or request duration. ### Method `PrintRequest` ### Parameters - `req` (*http.Request) - The HTTP request to print. ``` -------------------------------- ### Flusher Source: https://pkg.go.dev/github.com/henvic/httpretty Flusher defines how logger prints requests. Logger can print without flushing, when they are available, or when the request is done. ```APIDOC ## Flusher ### Description Flusher defines how logger prints requests. Logger can print without flushing, when they are available, or when the request is done. ### Constants ```go const ( // NoBuffer strategy prints anything immediately, without buffering. // It has the issue of mingling concurrent requests in unpredictable ways. NoBuffer Flusher = iota // OnReady buffers and prints each step of the request or response (header, body) whenever they are ready. // It reduces mingling caused by mingling but does not give any ordering guarantee, so responses can still be out of order. OnReady // OnEnd buffers the whole request and flushes it once, in the end. OnEnd ) ``` ### Type Definition ```go type Flusher int ``` ``` -------------------------------- ### Logger.SetFlusher Source: https://pkg.go.dev/github.com/henvic/httpretty SetFlusher sets the flush strategy for the logger. ```APIDOC ## Logger.SetFlusher ### Description Sets the flush strategy for the logger. ### Method `SetFlusher` ### Parameters - `f` (Flusher) - The flusher to set. ``` -------------------------------- ### DefaultSanitizers Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/header DefaultSanitizers contains a predefined map of common header names to their corresponding sanitization functions. This map includes sanitizers for Authorization, Set-Cookie, Cookie, and Proxy-Authorization headers. ```APIDOC ## DefaultSanitizers ### Description DefaultSanitizers contains a list of sanitizers to be used for common headers. ### Value ```go var DefaultSanitizers = map[string]SanitizeHeaderFunc{ "Authorization": AuthorizationSanitizer, "Set-Cookie": SetCookieSanitizer, "Cookie": CookieSanitizer, "Proxy-Authorization": AuthorizationSanitizer, } ``` ``` -------------------------------- ### Escape String Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/color Escapes a given string for safe terminal display, ensuring that ANSI escape codes are properly handled. ```APIDOC ## func Escape ### Description Escape text for terminal. ### Signature ```go func Escape(s string) string ``` ``` -------------------------------- ### Logger.SetBodyFilter Source: https://pkg.go.dev/github.com/henvic/httpretty SetBodyFilter allows you to set a function to skip printing a body. Pass nil to remove the body filter. This method is concurrency safe. ```APIDOC ## Logger.SetBodyFilter ### Description Allows you to set a function to skip printing a body. Pass nil to remove the body filter. This method is concurrency safe. ### Method `SetBodyFilter` ### Parameters - `f` (BodyFilter) - The function to use for filtering the request/response body. ``` -------------------------------- ### AuthorizationSanitizer Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/header Sanitizes Authorization and Proxy-Authorization headers by removing potentially sensitive information. ```APIDOC ## AuthorizationSanitizer ### Description AuthorizationSanitizer is used to sanitize Authorization and Proxy-Authorization headers. ### Signature ```go func AuthorizationSanitizer(unsafe string) string ``` ``` -------------------------------- ### Define Logger Struct Source: https://pkg.go.dev/github.com/henvic/httpretty Defines the Logger struct used for HTTP traffic logging. It includes numerous boolean and configuration fields to control what information is logged, such as request/response bodies, headers, and TLS details. Use this struct to configure the logging behavior. ```go type Logger struct { // SkipRequestInfo avoids printing a line showing the request URI on all requests plus a line // containing the remote address on server-side requests. SkipRequestInfo bool // Time the request began and its duration. Time bool // TLS information, such as certificates and ciphers. // BUG(henvic): Currently, the TLS information prints after the response header, although it // should be printed before the request header. TLS bool // RequestHeader set by the client or received from the server. RequestHeader bool // RequestBody sent by the client or received by the server. RequestBody bool // ResponseHeader received by the client or set by the HTTP handlers. ResponseHeader bool // ResponseBody received by the client or set by the server. ResponseBody bool // SkipSanitize bypasses sanitizing headers containing credentials (such as Authorization). SkipSanitize bool // Colors set ANSI escape codes that terminals use to print text in different colors. Colors bool // Align HTTP headers. Align bool // Formatters for the request and response bodies. // No standard formatters are used. You need to add what you want to use explicitly. // We provide a JSONFormatter for convenience (add it manually). Formatters []Formatter // MaxRequestBody the logger can print. // If value is not set and Content-Length is not sent, 4096 bytes is considered. MaxRequestBody int64 // MaxResponseBody the logger can print. // If value is not set and Content-Length is not sent, 4096 bytes is considered. MaxResponseBody int64 // contains filtered or unexported fields } ``` -------------------------------- ### Define a Header Sanitization Function Type Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/header SanitizeHeaderFunc defines the signature for functions that sanitize individual header values. Any function matching this signature can be used with the Sanitize function. ```go type SanitizeHeaderFunc func(string) string ``` -------------------------------- ### Define Default Sanitizers for HTTP Headers Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/header DefaultSanitizers is a map containing predefined sanitization functions for common HTTP headers like Authorization, Set-Cookie, Cookie, and Proxy-Authorization. Use this map directly or as a base for custom sanitizer configurations. ```go var DefaultSanitizers = map[string]SanitizeHeaderFunc{ "Authorization": AuthorizationSanitizer, "Set-Cookie": SetCookieSanitizer, "Cookie": CookieSanitizer, "Proxy-Authorization": AuthorizationSanitizer, } ``` -------------------------------- ### Logger.RoundTripper Source: https://pkg.go.dev/github.com/henvic/httpretty RoundTripper returns a RoundTripper that uses the logger. ```APIDOC ## Logger.RoundTripper ### Description Returns a RoundTripper that uses the logger. ### Method `RoundTripper` ### Parameters - `rt` (http.RoundTripper) - The original RoundTripper. ### Returns - `http.RoundTripper` - A new RoundTripper that logs requests and responses. ``` -------------------------------- ### Escape text for terminal Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/color Use this function to escape text for terminal display, ensuring proper rendering of ANSI escape codes. ```go func Escape(s string) string ``` -------------------------------- ### Sanitize Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/header Sanitizes a map of HTTP headers using a provided set of sanitizers. It iterates through the headers and applies the corresponding sanitizer function if available. ```APIDOC ## Sanitize ### Description Sanitize list of headers. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ can be consulted for header syntax. ### Signature ```go func Sanitize(sanitizers map[string]SanitizeHeaderFunc, headers http.Header) http.Header ``` ``` -------------------------------- ### CookieSanitizer Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/header Sanitizes Cookie headers by removing potentially sensitive information. ```APIDOC ## CookieSanitizer ### Description CookieSanitizer is used to sanitize Cookie header. ### Signature ```go func CookieSanitizer(unsafe string) string ``` ``` -------------------------------- ### JSONFormatter Structure Source: https://pkg.go.dev/github.com/henvic/httpretty JSONFormatter is a struct that can be used to format JSON content. You can integrate external libraries like github.com/tidwall/pretty for enhanced formatting. ```go type JSONFormatter struct{} ``` -------------------------------- ### Attribute Type Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/color Defines an Attribute type, which represents a single SGR (Select Graphic Rendition) code used for terminal formatting. This includes base attributes, foreground colors, and background colors. ```APIDOC ## type Attribute ### Description Attribute defines a single SGR (Select Graphic Rendition) code. ### Definition ```go type Attribute int ``` ### Constants #### Base Attributes ```go const ( Reset Attribute = iota Bold Faint Italic Underline BlinkSlow BlinkRapid ReverseVideo Concealed CrossedOut ) ``` #### Foreground Text Colors ```go const ( FgBlack Attribute = iota + 30 FgRed FgGreen FgYellow FgBlue FgMagenta FgCyan FgWhite ) ``` #### Foreground Hi-Intensity Text Colors ```go const ( FgHiBlack Attribute = iota + 90 FgHiRed FgHiGreen FgHiYellow FgHiBlue FgHiMagenta FgHiCyan FgHiWhite ) ``` #### Background Text Colors ```go const ( BgBlack Attribute = iota + 40 BgRed BgGreen BgYellow BgBlue BgMagenta BgCyan BgWhite ) ``` #### Background Hi-Intensity Text Colors ```go const ( BgHiBlack Attribute = iota + 100 BgHiRed BgHiGreen BgHiYellow BgHiBlue BgHiMagenta BgHiCyan BgHiWhite ) ``` ``` -------------------------------- ### BodyFilter Source: https://pkg.go.dev/github.com/henvic/httpretty BodyFilter allows you to skip printing a HTTP body based on its associated Header. It can be used for omitting HTTP Request and Response bodies. You can filter by checking properties such as Content-Type or Content-Length. ```APIDOC ## BodyFilter ### Description BodyFilter allows you to skip printing a HTTP body based on its associated Header. It can be used for omitting HTTP Request and Response bodies. You can filter by checking properties such as Content-Type or Content-Length. On a HTTP server, this function is called even when no body is present due to http.Request always carrying a non-nil value. ### Type Definition ```go type BodyFilter func(h http.Header) (skip bool, err error) ``` ``` -------------------------------- ### Sanitize Authorization and Proxy-Authorization Headers Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/header AuthorizationSanitizer is a function designed to clean sensitive data within Authorization and Proxy-Authorization headers. It is part of the default sanitizers provided by the header package. ```go func AuthorizationSanitizer(unsafe string) string ``` -------------------------------- ### SetCookieSanitizer Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/header Sanitizes Set-Cookie headers by removing potentially sensitive information. ```APIDOC ## SetCookieSanitizer ### Description SetCookieSanitizer is used to sanitize Set-Cookie header. ### Signature ```go func SetCookieSanitizer(unsafe string) string ``` ``` -------------------------------- ### Sanitize Set-Cookie Headers Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/header SetCookieSanitizer is a dedicated function for cleaning Set-Cookie headers. It is used to protect sensitive information that might be included in HTTP Set-Cookie directives. ```go func SetCookieSanitizer(unsafe string) string ``` -------------------------------- ### Sanitize Cookie Headers Source: https://pkg.go.dev/github.com/henvic/httpretty/internal/header CookieSanitizer is a function specifically for sanitizing the content of Cookie headers. It ensures that sensitive information within cookies is masked or removed. ```go func CookieSanitizer(unsafe string) string ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.