utils

package
v0.0.0-...-50e84b0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHeader

func AddHeader(data []byte, key string, val string) []byte

AddHeader adds a header to a request/response. The data array requires a valid format validated with IsRequest() or IsResponse().

func CreateResponse

func CreateResponse(code int, message string, body []byte) []byte

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 GenerateRandomBytes(n int) ([]byte, error)

func GenerateRandomHash

func GenerateRandomHash() string

func GenerateRandomInt

func GenerateRandomInt() int

func GetHeaderFieldName

func GetHeaderFieldName(headerLine []byte) []byte

func GetHeaderFieldValues

func GetHeaderFieldValues(data []byte, key []byte) [][]byte

GetHeaderFieldValues returns an array with all values of headers with the matching field value.

func IsRequest

func IsRequest(data []byte) bool

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 IsResponse(data []byte) bool

func IsValidHeader

func IsValidHeader(data []byte) bool

func ReadByContentLength

func ReadByContentLength(reader *bufio.Reader, n int) ([]byte, error)

ReadByContentLength reads from a stream expecting a fixed size.

func ReadChunks

func ReadChunks(reader *bufio.Reader) ([]byte, error)

ReadChunks reads from a stream expecting a chunked encoded http body.

func ReadHTTPBody

func ReadHTTPBody(br *bufio.Reader, data []byte, modifyHeaders bool) ([]byte, error)

ReadHTTPBody reads the expected body of an http stream. The data parameter must contain the previously received headers.

func ReadUntilBytes

func ReadUntilBytes(br *bufio.Reader, delim []byte) ([]byte, error)

ReadUntilBytes reads from a stream until the occurance of the delimiter.

func RemoveHeader

func RemoveHeader(data []byte, key string, index int) []byte

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

func SetHeaderValue(data []byte, key string, val string, index int) []byte

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.

func Tunnel

func Tunnel(connIn net.Conn, connOut net.Conn)

Tunnel reads incoming data from one connection and forwards to another connection

Types

This section is empty.

Jump to

Keyboard shortcuts

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