Documentation ¶
Index ¶
- Constants
- func CheckBrowserSupportForJson(req *http.Request) (ok bool, err error)
- func DeleteHttpHeader(r *http.Request, headerNameToDelete string) (err error)
- func FindHttpHeader(req *http.Request, headerNameAsked string) (hdrNm string, err error)
- func GetCookieByName(req *http.Request, cookieName string) (cookie *http.Cookie, err error)
- func GetSingleHttpHeader(req *http.Request, headerName string) (h string, err error)
- func ParseRecordWeight(rwt string) (weight float32, err error)
- func PerformAverageHttpTest(test *AverageTest) (err error)
- func PerformSimpleHttpTest(test *SimpleTest) (err error)
- func ReceiveJSON(r *http.Request, receiver interface{}) (err error)
- func ReplyErrorInternal(rw http.ResponseWriter, err error)
- func ReplyErrorWithCode(rw http.ResponseWriter, httpStatusCode int, err error)
- func ReplyJSON(rw http.ResponseWriter, replyObject interface{})
- func ReplyJSONFast(rw http.ResponseWriter, replyObject interface{})
- func ReplyTextWithCode(rw http.ResponseWriter, httpStatusCode int, replyText string)
- type AcceptedMimeType
- type AcceptedMimeTypes
- type AverageTest
- type AverageTestParameter
- type AverageTestResult
- type SimpleTest
- type SimpleTestParameter
- type SimpleTestResult
Constants ¶
const ( ErrNoRecords = "no records" ErrSyntaxErrorInRecord = "syntax error in record: %s" ErrSyntaxErrorInWeight = "syntax error in weight: %s" ErrEndOfList = "EOL" )
const ( ErrHttpHeaderNameIsNotSet = "HTTP header name is not set" ErrHttpHeaderNameIsNotFound = "HTTP header name is not found" ErrFMultipleHttpHeaders = "multiple HTTP headers: %s" ErrFHttpHeaderIsNotFound = "HTTP header is not found: %s" )
Errors
const (
ErrFDuplicateCookie = "duplicate cookie: %s"
)
const (
ErrNullPointer = "null pointer"
)
Errors.
Variables ¶
This section is empty.
Functions ¶
func CheckBrowserSupportForJson ¶ added in v0.22.0
func DeleteHttpHeader ¶ added in v0.22.0
DeleteHttpHeader function tries to delete a header from the HTTP request.
func FindHttpHeader ¶ added in v0.22.0
FindHttpHeader function tries to find the HTTP header with name similar to the specified one. According to the Section 4.2 of RFC 2616, HTTP header names are case-insensitive. On success, it returns the exact header name which was found.
Notes. This function is useful for inspection of HTTP requests having incorrect HTTP headers. It tries to show an actual name of the incorrectly set header. For example, if a request has a header named 'CONtent-TyPe', this function will search for headers similar to 'Content-Type' and find the modified variant of it and return it as it is, i.e. as 'CONtent-TyPe'. Most users do not need this function.
func GetCookieByName ¶ added in v0.22.0
GetCookieByName reads a non-duplicate cookie. If a cookie is not found, null is returned.
func GetSingleHttpHeader ¶ added in v0.22.0
GetSingleHttpHeader reads exactly one, single HTTP header. If multiple headers are found, an error is returned. Unfortunately, Go language does not do this by default and returns only a first header value even when there are multiple values available. Such a behaviour may lead to unexpected errors.
func ParseRecordWeight ¶ added in v0.16.0
func PerformAverageHttpTest ¶
func PerformAverageHttpTest(test *AverageTest) (err error)
PerformAverageHttpTest function performs the simulation of an average HTTP test handler. It writes the received results into the 'ResultReceived' field of a test object.
func PerformSimpleHttpTest ¶
func PerformSimpleHttpTest(test *SimpleTest) (err error)
PerformSimpleHttpTest function performs the simulation of a simple HTTP test handler. It writes the received results into the 'ResultReceived' field of a test object.
func ReceiveJSON ¶
ReceiveJSON function receives an object encoded with JSON format from the HTTP request's body. The receiver must be a pointer.
func ReplyErrorInternal ¶
func ReplyErrorInternal(rw http.ResponseWriter, err error)
ReplyErrorInternal function replies to the HTTP request with an error and 'Internal Server Error' HTTP status code.
func ReplyErrorWithCode ¶
func ReplyErrorWithCode(rw http.ResponseWriter, httpStatusCode int, err error)
ReplyErrorWithCode function replies to the HTTP request with an error and the specified HTTP status code.
func ReplyJSON ¶
func ReplyJSON(rw http.ResponseWriter, replyObject interface{})
ReplyJSON function sends an object in JSON format to the HTTP output stream.
func ReplyJSONFast ¶
func ReplyJSONFast(rw http.ResponseWriter, replyObject interface{})
ReplyJSONFast function sends an object in JSON format to the HTTP output stream using the faster but less secure way than an ordinary 'ReplyJSON' method.
func ReplyTextWithCode ¶
func ReplyTextWithCode(rw http.ResponseWriter, httpStatusCode int, replyText string)
ReplyTextWithCode function replies to the HTTP request with the specified text and HTTP status code.
Types ¶
type AcceptedMimeType ¶ added in v0.16.0
func ParseRecord ¶ added in v0.16.0
func ParseRecord(rec string) (amt *AcceptedMimeType, err error)
type AcceptedMimeTypes ¶ added in v0.16.0
type AcceptedMimeTypes struct {
// contains filtered or unexported fields
}
AcceptedMimeTypes provides convenient access to a list of MIME types received from the 'Accept' HTTP header. The struct has a simple iterator which allows to list values with the 'Next' method. The first returned value is the most acceptable, i.e. a value with the greatest weight. The last returned value is the least acceptable, i.e. a value with the lowest weight. Please, note that the iterator is not protected by a mutex against simultaneous access for performance reasons.
func NewAcceptedMimeTypesFromHeader ¶ added in v0.16.0
func NewAcceptedMimeTypesFromHeader(hdr string) (amts *AcceptedMimeTypes, err error)
NewAcceptedMimeTypesFromHeader parses the provided 'Accept' HTTP header and returns an AcceptedMimeType object.
func (*AcceptedMimeTypes) Next ¶ added in v0.16.0
func (amts *AcceptedMimeTypes) Next() (amt *AcceptedMimeType, err error)
Next gets the next MIME type in the list. If no more items are available, an error is returned.
func (*AcceptedMimeTypes) Reset ¶ added in v0.16.0
func (amts *AcceptedMimeTypes) Reset()
Reset resets the iterator. Normally, such a method is not used in iterable objects, but since the Go programming language is very unusual and unique, for those who for some reason want to iterate values several times, this method may be useful.
type AverageTest ¶
type AverageTest struct { Parameter AverageTestParameter ResultExpected AverageTestResult ResultReceived AverageTestResult }
AverageTest is an average HTTP test.
type AverageTestParameter ¶
type AverageTestParameter struct { RequestMethod string RequestUrl string RequestHeaders http.Header RequestBody io.Reader RequestHandler http.HandlerFunc }
AverageTestParameter is a parameter of an average HTTP test.
type AverageTestResult ¶
type AverageTestResult struct { ResponseStatusCode int ResponseHeaders http.Header ResponseBody []byte }
AverageTestResult is a result of an average HTTP test.
type SimpleTest ¶
type SimpleTest struct { Parameter SimpleTestParameter ResultExpected SimpleTestResult ResultReceived SimpleTestResult }
SimpleTest is a simple HTTP test.
type SimpleTestParameter ¶
type SimpleTestParameter struct { RequestMethod string RequestUrl string RequestBody io.Reader RequestHandler http.HandlerFunc }
SimpleTestParameter is a parameter of a simple HTTP test.
type SimpleTestResult ¶
SimpleTestResult is a result of a simple HTTP test.