Documentation
¶
Index ¶
- Variables
- func AbsoluteRedirectHandle(w http.ResponseWriter, r *http.Request)
- func Base64DecodeHandle(w http.ResponseWriter, r *http.Request)
- func BasicAuthHandle(w http.ResponseWriter, r *http.Request)
- func BearerAuthHandle(w http.ResponseWriter, r *http.Request)
- func BrotliHandle(w http.ResponseWriter, r *http.Request)
- func CacheControlHandle(w http.ResponseWriter, r *http.Request)
- func CacheHandle(w http.ResponseWriter, r *http.Request)
- func CookiesHandle(w http.ResponseWriter, r *http.Request)
- func CookiesListHandle(w http.ResponseWriter, r *http.Request)
- func Cors(next http.Handler) http.Handler
- func DeflateHandle(w http.ResponseWriter, r *http.Request)
- func DelayHandle(w http.ResponseWriter, r *http.Request)
- func DeleteCookiesHandle(w http.ResponseWriter, r *http.Request)
- func DenyHandle(w http.ResponseWriter, r *http.Request)
- func DigestAuthHandle(w http.ResponseWriter, r *http.Request)
- func DripHandle(w http.ResponseWriter, r *http.Request)
- func EtagHandle(w http.ResponseWriter, r *http.Request)
- func GzipHandle(w http.ResponseWriter, r *http.Request)
- func HeadersHandle(w http.ResponseWriter, r *http.Request)
- func HiddenBasicAuthHandle(w http.ResponseWriter, r *http.Request)
- func HtmlSampleHandle(w http.ResponseWriter, r *http.Request)
- func ImageAcceptHandle(w http.ResponseWriter, r *http.Request)
- func ImageHandle(w http.ResponseWriter, r *http.Request)
- func IndexHandle(w http.ResponseWriter, r *http.Request)
- func IpHandle(w http.ResponseWriter, r *http.Request)
- func JSONSampleHandle(w http.ResponseWriter, r *http.Request)
- func JsonError(w http.ResponseWriter, err string, code int)
- func LinkPageHandle(w http.ResponseWriter, r *http.Request)
- func LinksHandle(w http.ResponseWriter, r *http.Request)
- func MethodsHandle(w http.ResponseWriter, r *http.Request)
- func NewRouter(middlewares ...func(http.Handler) http.Handler) *chi.Mux
- func RandomBytesHandle(w http.ResponseWriter, r *http.Request)
- func RangeHandle(w http.ResponseWriter, r *http.Request)
- func RedirectHandle(w http.ResponseWriter, r *http.Request)
- func RedirectToHandle(w http.ResponseWriter, r *http.Request)
- func RelativeRedirectHandle(w http.ResponseWriter, r *http.Request)
- func ResponseHeadersHandle(w http.ResponseWriter, r *http.Request)
- func RobotsHandle(w http.ResponseWriter, r *http.Request)
- func SetCookieHandle(w http.ResponseWriter, r *http.Request)
- func SetCookiesHandle(w http.ResponseWriter, r *http.Request)
- func StatusCodeHandle(w http.ResponseWriter, r *http.Request)
- func StreamNMessagesHandle(w http.ResponseWriter, r *http.Request)
- func StreamRandomBytesHandle(w http.ResponseWriter, r *http.Request)
- func TextError(w http.ResponseWriter, err string, code int)
- func UUIDHandle(w http.ResponseWriter, r *http.Request)
- func UserAgentHandle(w http.ResponseWriter, r *http.Request)
- func Utf8SampleHandle(w http.ResponseWriter, r *http.Request)
- func XMLSampleHandle(w http.ResponseWriter, r *http.Request)
- type AuthResponse
- type CookiesListResponse
- type CookiesResponse
- type ErrorResponse
- type HeadersResponse
- type IpResponse
- type MethodsResponse
- type StatusResponse
- type StreamResponse
- type UUIDResponse
- type UserAgentResponse
Constants ¶
This section is empty.
Variables ¶
var RenderError func(http.ResponseWriter, string, int) = JsonError
RenderError renders the error message. It renders JSON by default and it can be overridden on program's `init` function.
var RenderResponse func(http.ResponseWriter, int, interface{}) = renderJson
RenderResponse is the default renderer function used by httpbulb. It renders JSON by default and it can be overridden on program's `init` function.
Functions ¶
func AbsoluteRedirectHandle ¶ added in v0.8.0
func AbsoluteRedirectHandle(w http.ResponseWriter, r *http.Request)
AbsoluteRedirectHandle is a http handler that makes 302/3XX redirects `n` times. `Location` header is an absolute URL.
func Base64DecodeHandle ¶ added in v0.7.0
func Base64DecodeHandle(w http.ResponseWriter, r *http.Request)
Base64DecodeHandle decodes a base64 encoded string and returns the decoded value
func BasicAuthHandle ¶ added in v0.3.0
func BasicAuthHandle(w http.ResponseWriter, r *http.Request)
BasicAuthHandle prompts the user for authorization using HTTP Basic Auth. It returns 401 if not authorized.
func BearerAuthHandle ¶ added in v0.7.0
func BearerAuthHandle(w http.ResponseWriter, r *http.Request)
BearerAuthHandle prompts the user for authorization using bearer authentication
func BrotliHandle ¶ added in v0.2.0
func BrotliHandle(w http.ResponseWriter, r *http.Request)
BrotliHandle is the handler that returns a response compressed with brotli
func CacheControlHandle ¶ added in v0.11.0
func CacheControlHandle(w http.ResponseWriter, r *http.Request)
CacheControlHandle sets a Cache-Control header for n seconds
func CacheHandle ¶ added in v0.11.0
func CacheHandle(w http.ResponseWriter, r *http.Request)
CacheHandle returns a 304 if an If-Modified-Since header or If-None-Match is present. Returns the same as a `MethodsHandle` (/get) otherwise.
func CookiesHandle ¶ added in v0.4.0
func CookiesHandle(w http.ResponseWriter, r *http.Request)
CookiesHandle returns the cookies list, sent by the client
func CookiesListHandle ¶ added in v0.6.0
func CookiesListHandle(w http.ResponseWriter, r *http.Request)
CookiesListResponse returns a **list** with request cookies
func DeflateHandle ¶ added in v0.2.0
func DeflateHandle(w http.ResponseWriter, r *http.Request)
DeflateHandle is the handler that returns a response compressed with zlib
func DelayHandle ¶ added in v0.3.0
func DelayHandle(w http.ResponseWriter, r *http.Request)
DelayHandle returns the same response as the MethodsHandle, but with a delay
func DeleteCookiesHandle ¶ added in v0.4.0
func DeleteCookiesHandle(w http.ResponseWriter, r *http.Request)
DeleteCookiesHandle deletes the cookies passed in the query parameters, then redirects to /cookies
func DenyHandle ¶ added in v0.8.0
func DenyHandle(w http.ResponseWriter, r *http.Request)
DenyHandle returns a page denied by robots.txt rules.
func DigestAuthHandle ¶ added in v0.7.0
func DigestAuthHandle(w http.ResponseWriter, r *http.Request)
DigestAuthHandle prompts the user for authorization using HTTP Digest Auth.
func DripHandle ¶ added in v0.7.0
func DripHandle(w http.ResponseWriter, r *http.Request)
DripHandle drips data over a duration after an optional initial delay
func EtagHandle ¶ added in v0.11.0
func EtagHandle(w http.ResponseWriter, r *http.Request)
EtagHandle assumes the resource has the given etag and responds to If-None-Match and If-Match headers appropriately.
func GzipHandle ¶ added in v0.2.0
func GzipHandle(w http.ResponseWriter, r *http.Request)
GzipHandle is the handler that returns a response compressed with gzip
func HeadersHandle ¶ added in v0.1.1
func HeadersHandle(w http.ResponseWriter, r *http.Request)
HeadersHandle returns only the request headers. Check `HeadersResponse`.
func HiddenBasicAuthHandle ¶ added in v0.7.0
func HiddenBasicAuthHandle(w http.ResponseWriter, r *http.Request)
HiddenBasicAuthHandle prompts the user for authorization using HTTP Basic Auth. It returns 404 if not authorized.
func HtmlSampleHandle ¶ added in v0.10.0
func HtmlSampleHandle(w http.ResponseWriter, r *http.Request)
HtmlSampleHandle serves the html file
func ImageAcceptHandle ¶ added in v0.9.0
func ImageAcceptHandle(w http.ResponseWriter, r *http.Request)
ImageAcceptHandle returns an image based on the client's Accept header.
func ImageHandle ¶ added in v0.9.0
func ImageHandle(w http.ResponseWriter, r *http.Request)
ImageHandle returns a simple image of the type specified in the URL path. The supported image types are svg, jpeg, png, and webp.
func IndexHandle ¶ added in v0.13.0
func IndexHandle(w http.ResponseWriter, r *http.Request)
IndexHandle serves the index.html file
func IpHandle ¶ added in v0.1.1
func IpHandle(w http.ResponseWriter, r *http.Request)
IpHandle returns only the IP address. Check `IpResponse`.
func JSONSampleHandle ¶ added in v0.10.0
func JSONSampleHandle(w http.ResponseWriter, r *http.Request)
JSONSampleHandle serves the json file
func JsonError ¶
func JsonError(w http.ResponseWriter, err string, code int)
JsonError is a shortcut func for writing an error in `application/json`
func LinkPageHandle ¶ added in v0.7.0
func LinkPageHandle(w http.ResponseWriter, r *http.Request)
LinkPageHandle generates a page containing n links to other pages which do the same.
func LinksHandle ¶ added in v0.7.0
func LinksHandle(w http.ResponseWriter, r *http.Request)
LinksHandle redirects to first links page.
func MethodsHandle ¶ added in v0.1.1
func MethodsHandle(w http.ResponseWriter, r *http.Request)
MethodsHandle is the basic handler for the methods endpoint (GET, POST, PUT, PATCH, DELETE)
func NewRouter ¶
NewRouter returns a new chi.Mux with predefined http handlers. It also accepts chi middlewares.
func RandomBytesHandle ¶ added in v0.7.0
func RandomBytesHandle(w http.ResponseWriter, r *http.Request)
RandomBytesHandle returns `n` random bytes generated with given `seed`.
func RangeHandle ¶ added in v0.7.0
func RangeHandle(w http.ResponseWriter, r *http.Request)
RangeHandle streams n random bytes generated with given seed, at given chunk size per packet
func RedirectHandle ¶ added in v0.8.0
func RedirectHandle(w http.ResponseWriter, r *http.Request)
RedirectHandle is a http handler that makes 302/3XX redirects `n` times. `n` is a number in the URL path, if `n` is 1, it will redirect to `/get`. if `absolute` query param is true, `Location` header will be an absolute URL.
func RedirectToHandle ¶ added in v0.8.0
func RedirectToHandle(w http.ResponseWriter, r *http.Request)
RedirectToHandle is a http handler that makes 302/3XX redirects to the given URL
func RelativeRedirectHandle ¶ added in v0.8.0
func RelativeRedirectHandle(w http.ResponseWriter, r *http.Request)
RelativeRedirectHandle is a http handler that makes 302/3XX redirects `n` times. `Location` header is a relative URL.
func ResponseHeadersHandle ¶ added in v0.11.0
func ResponseHeadersHandle(w http.ResponseWriter, r *http.Request)
ResponseHeadersHandle returns the response headers as JSON response
func RobotsHandle ¶ added in v0.2.0
func RobotsHandle(w http.ResponseWriter, r *http.Request)
RobotsHandle returns the `text/plain` content for the robots.txt
func SetCookieHandle ¶ added in v0.4.0
func SetCookieHandle(w http.ResponseWriter, r *http.Request)
SetCookieHandle sets a cookie with the name and value passed in the URL path, then redirects to /cookies
func SetCookiesHandle ¶ added in v0.4.0
func SetCookiesHandle(w http.ResponseWriter, r *http.Request)
SetCookiesHandle sets the cookies passed from the query parameters, then redirects to /cookies
func StatusCodeHandle ¶ added in v0.11.1
func StatusCodeHandle(w http.ResponseWriter, r *http.Request)
StatusCodesHandle returns status code or random status code if more than one are given. This handler does not handle status codes lesser than 200 or greater than 599.
func StreamNMessagesHandle ¶ added in v0.3.0
func StreamNMessagesHandle(w http.ResponseWriter, r *http.Request)
StreamNMessagesHandle streams N json messages
func StreamRandomBytesHandle ¶ added in v0.7.0
func StreamRandomBytesHandle(w http.ResponseWriter, r *http.Request)
StreamRandomBytesHandle streams `n` random bytes generated with given `seed`, at given `chunk_size` per packet.
func TextError ¶ added in v0.7.0
func TextError(w http.ResponseWriter, err string, code int)
TextError is a shortcut func for writing an error in `text/plain`
func UUIDHandle ¶ added in v0.7.0
func UUIDHandle(w http.ResponseWriter, r *http.Request)
UUIDHandle returns a new UUID version 4
func UserAgentHandle ¶ added in v0.1.1
func UserAgentHandle(w http.ResponseWriter, r *http.Request)
UserAgentHandle returns only the user agent. Check `UserAgentResponse`.
func Utf8SampleHandle ¶ added in v0.10.0
func Utf8SampleHandle(w http.ResponseWriter, r *http.Request)
Utf8SampleHandle serves the utf8-encoded file
func XMLSampleHandle ¶ added in v0.10.0
func XMLSampleHandle(w http.ResponseWriter, r *http.Request)
XMLSampleHandle serves the xml file
Types ¶
type AuthResponse ¶ added in v0.3.0
type AuthResponse struct { Authenticated bool `json:"authenticated"` User string `json:"user,omitempty"` Token string `json:"token,omitempty"` }
AuthResponse is the response for the basic-auth endpoint
type CookiesListResponse ¶ added in v0.6.0
CookiesListResponse represents a response for the cookies-list endpoint. In this case, cookies are represented as a list (slice) of `http.Cookie`.
type CookiesResponse ¶ added in v0.4.0
CookiesResponse represents a response for the cookies endpoint It contains a map of cookies, which is cookie name and a list of its values.
type ErrorResponse ¶ added in v0.13.0
type ErrorResponse struct {
Error string `json:"error"`
}
ErrorResponse represents an error response from the server.
It is used to return errors in JSON format. It contains a single field, "error", which holds the error message.
type HeadersResponse ¶ added in v0.1.1
HeadersResponse is the response for the headers endpoint
type IpResponse ¶ added in v0.1.1
type IpResponse struct {
Origin string `json:"origin"`
}
IpResponse is the response for the ip endpoint
type MethodsResponse ¶
type MethodsResponse struct { // Args is a map of query parameters Args map[string][]string `json:"args"` // Data is the raw body of the request Data string `json:"data"` // Files is a map of files sent in the request Files map[string][]string `json:"files"` // Form is a map of form values sent in the request Form map[string][]string `json:"form"` // Headers is a map of headers sent in the request Headers map[string][]string `json:"headers"` // JSON is the parsed JSON body of the request JSON interface{} `json:"json"` // Origin is the IP address of the requester Origin string `json:"origin"` // URL is the full URL of the request URL string `json:"url"` // Gzipped is true if the request was compressed with gzip Gzipped bool `json:"gzipped,omitempty"` // Brotli is true if the request was compressed with brotli Brotli bool `json:"brotli,omitempty"` // Deflated is true if the request was compressed with zlib Deflated bool `json:"deflated,omitempty"` // Proto is the protocol of the request Proto string `json:"proto"` }
MethodsResponse is the response for the methods endpoint
type StatusResponse ¶ added in v0.1.1
type StatusResponse struct {
StatusText string `json:"status_text"`
}
StatusResponse is the response for the status endpoint
type StreamResponse ¶ added in v0.3.0
type StreamResponse struct { // ID is the ID of the message ID int `json:"id"` // Args is a map of query parameters Args map[string][]string `json:"args"` // Data is the raw body of the request Headers map[string][]string `json:"headers"` // Origin is the IP address of the requester Origin string `json:"origin"` // URL is the full URL of the request URL string `json:"url"` }
StreamResponse represents a response for the stream endpoint
type UUIDResponse ¶ added in v0.7.0
type UUIDResponse struct {
UUID string `json:"uuid"`
}
UUIDResponse represents a response with a UUID string.
type UserAgentResponse ¶ added in v0.1.1
type UserAgentResponse struct {
UserAgent string `json:"user-agent"`
}
UserAgentResponse is the response for the user-agent endpoint