Documentation ¶
Index ¶
- func AddHeader(data []byte, key string, val string) []byte
- func CreateResponse(code int, message string, body []byte) []byte
- func GenerateRandomBytes(n int) ([]byte, error)
- func GenerateRandomHash() string
- func GenerateRandomInt() int
- func GetHeaderFieldName(headerLine []byte) []byte
- func GetHeaderFieldValues(data []byte, key []byte) [][]byte
- func IsRequest(data []byte) bool
- func IsResponse(data []byte) bool
- func IsValidHeader(data []byte) bool
- func ReadByContentLength(reader *bufio.Reader, n int) ([]byte, error)
- func ReadChunks(reader *bufio.Reader) ([]byte, error)
- func ReadHTTPBody(br *bufio.Reader, data []byte, modifyHeaders bool) ([]byte, error)
- func ReadUntilBytes(br *bufio.Reader, delim []byte) ([]byte, error)
- func RemoveHeader(data []byte, key string, index int) []byte
- func SetHeaderValue(data []byte, key string, val string, index int) []byte
- func Tunnel(connIn net.Conn, connOut net.Conn)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddHeader ¶
AddHeader adds a header to a request/response. The data array requires a valid format validated with IsRequest() or IsResponse().
func CreateResponse ¶
CreateResponse returns a full http response with custom response code and body. The content-length header is set dynamically matching the body length.
func GenerateRandomBytes ¶
func GenerateRandomHash ¶
func GenerateRandomHash() string
func GenerateRandomInt ¶
func GenerateRandomInt() int
func GetHeaderFieldName ¶
func GetHeaderFieldValues ¶
GetHeaderFieldValues returns an array with all values of headers with the matching field value.
func IsRequest ¶
IsRequest checks whether a data array has a valid http request format. It considers the request line, lines separated by \r\n and the occurance of \r\n\r\n.
func IsResponse ¶
func IsValidHeader ¶
func ReadByContentLength ¶
ReadByContentLength reads from a stream expecting a fixed size.
func ReadChunks ¶
ReadChunks reads from a stream expecting a chunked encoded http body.
func ReadHTTPBody ¶
ReadHTTPBody reads the expected body of an http stream. The data parameter must contain the previously received headers.
func ReadUntilBytes ¶
ReadUntilBytes reads from a stream until the occurance of the delimiter.
func RemoveHeader ¶
RemoveHeader removes a header with a certain key. If index is 0, all headers with the matching key will be removed. If index is > 0, only the nth occurance of the header will be removed.
func SetHeaderValue ¶
SetHeaderValue replaces the value of header with a certain key. If index is 0, all headers with the matching key will be modified. If index is > 0, only the nth occurance of the header will be modified.
Types ¶
This section is empty.