proto

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2015 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package proto provides byte-level interaction with HTTP request payload.

Example of HTTP payload for future references, new line symbols escaped:

POST /upload HTTP/1.1\r\n
User-Agent: Gor\r\n
Content-Length: 11\r\n
\r\n
Hello world

GET /index.html HTTP/1.1\r\n
User-Agent: Gor\r\n
\r\n
\r\n

Index

Constants

This section is empty.

Variables

View Source
var CLRF = []byte("\r\n")

In HTTP newline defined by 2 bytes (for both windows and *nix support)

View Source
var EmptyLine = []byte("\r\n\r\n")

New line acts as separator: end of Headers or Body (in some cases)

View Source
var HeaderDelim = []byte(": ")

Separator for Header line. Header looks like: `HeaderName: value`

Functions

func AddHeader

func AddHeader(payload, name, value []byte) []byte

AddHeader takes http payload and appends new header to the start of headers section Returns modified request payload

func Body

func Body(payload []byte) []byte

Body returns request/response body

func Header(payload, name []byte) []byte

Header returns header value, if header not found, value will be blank

func IsHTTPPayload

func IsHTTPPayload(payload []byte) bool

func MIMEHeadersEndPos

func MIMEHeadersEndPos(payload []byte) int

MIMEHeadersEndPos finds end of the Headers section, which should end with empty line.

func MIMEHeadersStartPos

func MIMEHeadersStartPos(payload []byte) int

MIMEHeadersStartPos finds start of Headers section It just finds position of second line (first contains location and method).

func Method

func Method(payload []byte) []byte

Method returns HTTP method

func Path

func Path(payload []byte) []byte

Path takes payload and retuns request path: Split(firstLine, ' ')[1]

func PathParam

func PathParam(payload, name []byte) (value []byte, valueStart, valueEnd int)

PathParam returns URL query attribute by given name, if no found: valueStart will be -1

func SetHeader

func SetHeader(payload, name, value []byte) []byte

SetHeader sets header value. If header not found it creates new one. Returns modified request payload

func SetHost

func SetHost(payload, url, host []byte) []byte

SetHost updates Host header for HTTP/1.1 or updates host in path for HTTP/1.0 or Proxy requests Returns modified payload

func SetPath

func SetPath(payload, path []byte) []byte

SetPath takes payload, sets new path and returns modified payload

func SetPathParam

func SetPathParam(payload, name, value []byte) []byte

SetPathParam takes payload and updates path Query attribute If query param not found, it will append new Returns modified payload

func Status

func Status(payload []byte) []byte

Status returns response status. It happend to be in same position as request payload path

Types

This section is empty.

Jump to

Keyboard shortcuts

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