Package httpbin provides a simple HTTP request and response testing server, modeled on the original httpbin.org Python project.
Default configuration values
DefaultDefaultParams defines the DefaultParams that are used by default. In general, these should match the original httpbin.org's defaults.
This section is empty.
DefaultParams defines default parameter values
HTTPBin contains the business logic
New creates a new HTTPBin instance
AbsoluteRedirect responds with an HTTP 302 redirect a given number of times
Anything returns anything that is passed to request.
Base64 - encodes/decodes input data
BasicAuth requires basic authentication
Bearer - Prompts the user for authorization using bearer authentication.
Bytes returns N random bytes generated with an optional seed
Cache returns a 304 if an If-Modified-Since or an If-None-Match header is present, otherwise returns the same response as Get.
CacheControl sets a Cache-Control header for N seconds for /cache/N requests
Cookies responds with the cookies in the incoming request
Deflate returns a gzipped response
Delay waits for a given amount of time before responding, where the time may be specified as a golang-style duration or seconds in floating point.
DeleteCookies deletes cookies specified in query params and redirects to Cookies endpoint
Deny renders a basic page that robots should never access
DigestAuth handles a simple implementation of HTTP Digest Authentication, which supports the "auth" QOP and the MD5 and SHA-256 crypto algorithms.
/digest-auth/<qop>/<user>/<passwd> /digest-auth/<qop>/<user>/<passwd>/<algorithm>
Drip simulates a slow HTTP server by writing data over a given duration after an optional initial delay.
Because this endpoint is intended to simulate a slow HTTP connection, it intentionally does NOT use chunked transfer encoding even though its implementation writes the response incrementally.
See Stream (/stream) or StreamBytes (/stream-bytes) for endpoints that respond using chunked transfer encoding.
DumpRequest - returns the given request in its HTTP/1.x wire representation. The returned representation is an approximation only; some details of the initial request are lost while parsing it into an http.Request. In particular, the order and case of header field names are lost.
ETag assumes the resource has the given etag and responds to If-None-Match and If-Match headers appropriately.
Env - returns environment variables with HTTPBIN_ prefix, if any pre-configured by operator
FormsPost renders an HTML form that submits a request to the /post endpoint
Get handles HTTP GET requests
Gzip returns a gzipped response
HTML renders a basic HTML page
func (*HTTPBin) Handler ¶Handler returns an http.Handler that exposes all HTTPBin endpoints
Headers echoes the incoming request headers
HiddenBasicAuth requires HTTP Basic authentication but returns a status of 404 if the request is unauthorized
Hostname - returns the hostname.
IP echoes the IP address of the incoming request
Image responds with an image of a specific kind, from /image/<kind>
ImageAccept responds with an appropriate image based on the Accept header
Index renders an HTML index page
JSON - returns a sample json
Links redirects to the first page in a series of N links
Range returns up to N bytes, with support for HTTP Range requests.
This departs from original httpbin in a few ways:
param `chunk_size` IS NOT supported
param `duration` IS supported, but functions more as a delay before the whole response is written
multiple ranges ARE correctly supported (i.e. `Range: bytes=0-1,2-3` will return a multipart/byteranges response)
Most of the heavy lifting is done by the stdlib's http.ServeContent, which handles range requests automatically. Supporting chunk sizes would require an extensive reimplementation, especially to support multiple ranges for correctness. For now, we choose not to take that work on.
Redirect responds with 302 redirect a given number of times. Defaults to a relative redirect, but an ?absolute=true query param will trigger an absolute redirect.
RedirectTo responds with a redirect to a specific URL with an optional status code, which defaults to 302
RelativeRedirect responds with an HTTP 302 redirect a given number of times
func (*HTTPBin) RequestWithBody ¶RequestWithBody handles POST, PUT, and PATCH requests by responding with a JSON representation of the incoming request.
ResponseHeaders sets every incoming query parameter as a response header and returns the headers serialized as JSON.
If the Content-Type query parameter is given and set to a "dangerous" value (i.e. one that might be rendered as HTML in a web browser), the keys and values in the JSON response body will be escaped.
Robots renders a basic robots.txt file
SSE writes a stream of events over a duration after an optional initial delay.
ServeHTTP implememnts the http.Handler interface.
SetCookies sets cookies as specified in query params and redirects to Cookies endpoint
Status responds with the specified status code. TODO: support random choice from multiple, optionally weighted status codes.
Stream responds with max(n, 100) lines of JSON-encoded request data.
StreamBytes streams N random bytes generated with an optional seed in chunks of a given size.
Trailers adds the header keys and values specified in the request's query parameters as HTTP trailers in the response.
Trailers are returned in canonical form. Any forbidden trailer will result in an error.
UTF8 renders an HTML encoding stress test
UUID - responds with a generated UUID
Unstable - returns 500, sometimes
UserAgent echoes the incoming User-Agent header
WebSocketEcho - simple websocket echo server, where the max fragment size and max message size can be controlled by clients.
XML responds with an XML document
type Observer func(result Result)
Observer is a function that will be called with the details of a handled request, which can be used for logging, instrumentation, etc
StdLogObserver creates an Observer that will log each request in structured format using the given stdlib logger
OptionFunc uses the "functional options" pattern to customize an HTTPBin instance
func WithAllowedRedirectDomains ¶ added in v2.5.1WithAllowedRedirectDomains limits the domains to which the /redirect-to endpoint will redirect traffic.
WithDefaultParams sets the default params handlers will use
WithEnv sets the HTTPBIN_-prefixed environment variables reported by the /env endpoint.
WithExcludeHeaders sets the headers to exclude in outgoing responses, to prevent possible information leakage.
WithHostname sets the hostname to return via the /hostname endpoint.
WithMaxDuration sets the maximum amount of time httpbin may take to respond
WithObserver sets the request observer callback
WithPrefix sets the path prefix
func WithUnsafeAllowDangerousResponses() OptionFunc
WithUnsafeAllowDangerousResponses means endpoints that allow clients to specify a response Conntent-Type WILL NOT escape HTML entities in the response body, which can enable (e.g.) reflected XSS attacks.
This configuration is only supported for backwards compatibility if absolutely necessary.
Result is the result of handling a request, used for instrumentation
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4