Documentation ¶
Index ¶
- Constants
- type HTTPBin
- func (h *HTTPBin) AbsoluteRedirect(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) BasicAuth(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) Bytes(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) Cache(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) CacheControl(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) Cookies(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) Deflate(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) Delay(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) DeleteCookies(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) Deny(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) DigestAuth(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) Drip(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) ETag(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) FormsPost(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) Get(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) Gzip(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) HTML(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) Handler() http.Handler
- func (h *HTTPBin) Headers(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) HiddenBasicAuth(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) IP(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) Image(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) ImageAccept(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) Index(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) Links(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) Range(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) Redirect(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) RedirectTo(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) RelativeRedirect(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) RequestWithBody(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) ResponseHeaders(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) Robots(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) SetCookies(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) Status(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) Stream(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) StreamBytes(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) UTF8(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) UserAgent(w http.ResponseWriter, r *http.Request)
- func (h *HTTPBin) XML(w http.ResponseWriter, r *http.Request)
- type Options
Constants ¶
const ( DefaultMaxMemory int64 = 1024 * 1024 DefaultMaxDuration = 10 * time.Second )
Default configuration values
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTPBin ¶
type HTTPBin struct {
// contains filtered or unexported fields
}
HTTPBin contains the business logic
func NewHTTPBin ¶
func NewHTTPBin() *HTTPBin
NewHTTPBin creates a new HTTPBin instance with default options
func NewHTTPBinWithOptions ¶
NewHTTPBinWithOptions creates a new HTTPBin instance with the given options
func (*HTTPBin) AbsoluteRedirect ¶
func (h *HTTPBin) AbsoluteRedirect(w http.ResponseWriter, r *http.Request)
AbsoluteRedirect responds with an HTTP 302 redirect a given number of times
func (*HTTPBin) BasicAuth ¶
func (h *HTTPBin) BasicAuth(w http.ResponseWriter, r *http.Request)
BasicAuth requires basic authentication
func (*HTTPBin) Bytes ¶
func (h *HTTPBin) Bytes(w http.ResponseWriter, r *http.Request)
Bytes returns N random bytes generated with an optional seed
func (*HTTPBin) Cache ¶
func (h *HTTPBin) Cache(w http.ResponseWriter, r *http.Request)
Cache returns a 304 if an If-Modified-Since or an If-None-Match header is present, otherwise returns the same response as Get.
func (*HTTPBin) CacheControl ¶
func (h *HTTPBin) CacheControl(w http.ResponseWriter, r *http.Request)
CacheControl sets a Cache-Control header for N seconds for /cache/N requests
func (*HTTPBin) Cookies ¶
func (h *HTTPBin) Cookies(w http.ResponseWriter, r *http.Request)
Cookies responds with the cookies in the incoming request
func (*HTTPBin) Deflate ¶
func (h *HTTPBin) Deflate(w http.ResponseWriter, r *http.Request)
Deflate returns a gzipped response
func (*HTTPBin) Delay ¶
func (h *HTTPBin) Delay(w http.ResponseWriter, r *http.Request)
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.
func (*HTTPBin) DeleteCookies ¶
func (h *HTTPBin) DeleteCookies(w http.ResponseWriter, r *http.Request)
DeleteCookies deletes cookies specified in query params and redirects to Cookies endpoint
func (*HTTPBin) Deny ¶
func (h *HTTPBin) Deny(w http.ResponseWriter, r *http.Request)
Deny renders a basic page that robots should never access
func (*HTTPBin) DigestAuth ¶
func (h *HTTPBin) DigestAuth(w http.ResponseWriter, r *http.Request)
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>
func (*HTTPBin) Drip ¶
func (h *HTTPBin) Drip(w http.ResponseWriter, r *http.Request)
Drip returns data over a duration after an optional initial delay, then (optionally) returns with the given status code.
func (*HTTPBin) ETag ¶
func (h *HTTPBin) ETag(w http.ResponseWriter, r *http.Request)
ETag assumes the resource has the given etag and response to If-None-Match and If-Match headers appropriately.
func (*HTTPBin) FormsPost ¶
func (h *HTTPBin) FormsPost(w http.ResponseWriter, r *http.Request)
FormsPost renders an HTML form that submits a request to the /post endpoint
func (*HTTPBin) Get ¶
func (h *HTTPBin) Get(w http.ResponseWriter, r *http.Request)
Get handles HTTP GET requests
func (*HTTPBin) Gzip ¶
func (h *HTTPBin) Gzip(w http.ResponseWriter, r *http.Request)
Gzip returns a gzipped response
func (*HTTPBin) HTML ¶
func (h *HTTPBin) HTML(w http.ResponseWriter, r *http.Request)
HTML renders a basic HTML page
func (*HTTPBin) Headers ¶
func (h *HTTPBin) Headers(w http.ResponseWriter, r *http.Request)
Headers echoes the incoming request headers
func (*HTTPBin) HiddenBasicAuth ¶
func (h *HTTPBin) HiddenBasicAuth(w http.ResponseWriter, r *http.Request)
HiddenBasicAuth requires HTTP Basic authentication but returns a status of 404 if the request is unauthorized
func (*HTTPBin) IP ¶
func (h *HTTPBin) IP(w http.ResponseWriter, r *http.Request)
IP echoes the IP address of the incoming request
func (*HTTPBin) Image ¶
func (h *HTTPBin) Image(w http.ResponseWriter, r *http.Request)
Image responds with an image of a specific kind, from /image/<kind>
func (*HTTPBin) ImageAccept ¶
func (h *HTTPBin) ImageAccept(w http.ResponseWriter, r *http.Request)
ImageAccept responds with an appropriate image based on the Accept header
func (*HTTPBin) Index ¶
func (h *HTTPBin) Index(w http.ResponseWriter, r *http.Request)
Index renders an HTML index page
func (*HTTPBin) Links ¶
func (h *HTTPBin) Links(w http.ResponseWriter, r *http.Request)
Links redirects to the first page in a series of N links
func (*HTTPBin) Range ¶
func (h *HTTPBin) Range(w http.ResponseWriter, r *http.Request)
Range returns up to N bytes, with support for HTTP Range requests.
This departs from httpbin by not supporting the chunk_size or duration parameters.
func (*HTTPBin) Redirect ¶
func (h *HTTPBin) Redirect(w http.ResponseWriter, r *http.Request)
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.
func (*HTTPBin) RedirectTo ¶
func (h *HTTPBin) RedirectTo(w http.ResponseWriter, r *http.Request)
RedirectTo responds with a redirect to a specific URL with an optional status code, which defaults to 302
func (*HTTPBin) RelativeRedirect ¶
func (h *HTTPBin) RelativeRedirect(w http.ResponseWriter, r *http.Request)
RelativeRedirect responds with an HTTP 302 redirect a given number of times
func (*HTTPBin) RequestWithBody ¶
func (h *HTTPBin) RequestWithBody(w http.ResponseWriter, r *http.Request)
RequestWithBody handles POST, PUT, and PATCH requests
func (*HTTPBin) ResponseHeaders ¶
func (h *HTTPBin) ResponseHeaders(w http.ResponseWriter, r *http.Request)
ResponseHeaders responds with a map of header values
func (*HTTPBin) Robots ¶
func (h *HTTPBin) Robots(w http.ResponseWriter, r *http.Request)
Robots renders a basic robots.txt file
func (*HTTPBin) SetCookies ¶
func (h *HTTPBin) SetCookies(w http.ResponseWriter, r *http.Request)
SetCookies sets cookies as specified in query params and redirects to Cookies endpoint
func (*HTTPBin) Status ¶
func (h *HTTPBin) Status(w http.ResponseWriter, r *http.Request)
Status responds with the specified status code. TODO: support random choice from multiple, optionally weighted status codes.
func (*HTTPBin) Stream ¶
func (h *HTTPBin) Stream(w http.ResponseWriter, r *http.Request)
Stream responds with max(n, 100) lines of JSON-encoded request data.
func (*HTTPBin) StreamBytes ¶
func (h *HTTPBin) StreamBytes(w http.ResponseWriter, r *http.Request)
StreamBytes streams N random bytes generated with an optional seed in chunks of a given size.
func (*HTTPBin) UTF8 ¶
func (h *HTTPBin) UTF8(w http.ResponseWriter, r *http.Request)
UTF8 renders an HTML encoding stress test
type Options ¶
type Options struct { // How much memory a request is allowed to consume in bytes, as a limit on // the size of incoming request bodies and on responses generated MaxMemory int64 // Maximum duration of a request, for those requests that allow user // control over timing (e.g. /delay) MaxDuration time.Duration }
Options are used to configure HTTPBin