httphelper

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: MIT Imports: 12 Imported by: 3

README

HTTP Helper

This Package helps in processing and testing HTTP Requests.

This Package contains various useful Functions which help in processing HTTP Requests:

  • Receiving an Object encoded into HTTP Request's Body with JSON Format;
  • Replying with an Object encoded into JSON Format;
  • Replying with a Text Message and HTTP Status Code;
  • Replying with an Error and HTTP Status Code;
  • Performing a simple automated HTTP Handler Test using the built-in 'httptest' Package.

Documentation

Index

Constants

View Source
const (
	ErrHTTPHeaderNameIsNotSet   = "HTTP Header Name is not set"
	ErrHTTPHeaderNameIsNotFound = "HTTP Header Name is not found"
)

Errors

View Source
const (
	ErrNotPointer = "not a pointer"
)

Errors.

View Source
const (
	ErrNullPointer = "null pointer"
)

Errors.

Variables

This section is empty.

Functions

func DeleteHTTPHeader

func DeleteHTTPHeader(
	r *http.Request,
	headerNameToDelete string,
) error

DeleteHTTPHeader Function tries to delete a Header from the HTTP Request.

func FindHTTPHeader

func FindHTTPHeader(
	r *http.Request,
	headerNameAsked string,
) (string, error)

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, returns 'nil' and the exact Header Name which was found.

func PerformAverageHttpTest

func PerformAverageHttpTest(
	test *AverageTest,
) (err error)

PerformAverageHttpTest Function performs the Simulation of an average HTTP Test Handler. 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. Writes the received Results into the 'ResultReceived' Field of a Test Object.

func ReceiveJSON

func ReceiveJSON(
	r *http.Request,
	receiver interface{},
) (err error)

ReceiveJSON Function receives an Object encoded with JSON Format from the HTTP Request's Body.

func ReplyErrorInternal

func ReplyErrorInternal(
	w 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(
	w 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(
	w http.ResponseWriter,
	replyObject interface{},
)

ReplyJSON Function sends an Object in JSON Format to the HTTP Output Stream.

func ReplyJSONFast

func ReplyJSONFast(
	w 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(
	w http.ResponseWriter,
	httpStatusCode int,
	replyText string,
)

ReplyTextWithCode Function replies to the HTTP Request with the specified Text and HTTP Status Code.

Types

type AverageTest

type AverageTest struct {
	Parameter      AverageTestParameter
	ResultExpected AverageTestResult
	ResultReceived AverageTestResult
}

AverageTest Type is a Type of a average HTTP Test.

type AverageTestParameter

type AverageTestParameter struct {
	RequestMethod  string
	RequestUrl     string
	RequestHeaders http.Header
	RequestBody    io.Reader
	RequestHandler http.HandlerFunc
}

AverageTestParameter Type is a Parameter of a average HTTP Test.

type AverageTestResult

type AverageTestResult struct {
	ResponseStatusCode int
	ResponseHeaders    http.Header
	ResponseBody       []byte
}

AverageTestResult Type is a Result of a average HTTP Test.

type SimpleTest

type SimpleTest struct {
	Parameter      SimpleTestParameter
	ResultExpected SimpleTestResult
	ResultReceived SimpleTestResult
}

SimpleTest Type is a Type of a simple HTTP Test.

type SimpleTestParameter

type SimpleTestParameter struct {
	RequestMethod  string
	RequestUrl     string
	RequestBody    io.Reader
	RequestHandler http.HandlerFunc
}

SimpleTestParameter Type is a Parameter of a simple HTTP Test.

type SimpleTestResult

type SimpleTestResult struct {
	ResponseStatusCode int
	ResponseBodyString string
}

SimpleTestResult Type is a Result of a simple HTTP Test.

Jump to

Keyboard shortcuts

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