httpbulb

package module
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2024 License: MIT Imports: 26 Imported by: 0

README

httpbulb

Requirements

Go 1.18

Installation

go get -u github.com/niklak/httpbulb

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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)

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)

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 IpHandle added in v0.1.1

func IpHandle(w http.ResponseWriter, r *http.Request)

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)

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

func NewRouter() *chi.Mux

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)

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)

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)

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

type CookiesListResponse struct {
	Cookies []*http.Cookie `json:"cookies"`
}

type CookiesResponse added in v0.4.0

type CookiesResponse struct {
	Cookies map[string][]string `json:"cookies"`
}

type HeadersResponse added in v0.1.1

type HeadersResponse struct {
	Headers http.Header `json:"headers"`
}

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"`
}

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"`
}

type UserAgentResponse added in v0.1.1

type UserAgentResponse struct {
	UserAgent string `json:"user-agent"`
}

UserAgentResponse is the response for the user-agent endpoint

Jump to

Keyboard shortcuts

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