upgrade

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const HTTPVersion = "1.1"

HTTPVersion constant

View Source
const UsedWSVersion = 13

UsedWSVersion constant websocket version

View Source
const WSSalt = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"

WSSalt constant websocket salt

Variables

This section is empty.

Functions

This section is empty.

Types

type Header struct {
	Name   HeaderType
	Values HeaderValue
}

Header represents the data of a HTTP request header

func ReadHeader

func ReadHeader(b []byte) (*Header, error)

ReadHeader tries to parse an HTTP header from a byte array

type HeaderType

type HeaderType uint8

HeaderType represents all 'valid' HTTP request headers

const (
	Unknown HeaderType = iota
	Host
	Upgrade
	Connection
	Origin
	WSKey
	WSProtocol
	WSExtensions
	WSVersion
)

header types

type HeaderValue

type HeaderValue [][]byte

HeaderValue represents a unique or multiple header value(s)

type IncompleteRequest

type IncompleteRequest struct {
	MissingField string
}

Request misses fields (request-line or headers)

func (IncompleteRequest) Error

func (err IncompleteRequest) Error() string

type InvalidOriginPolicy

type InvalidOriginPolicy struct {
	Host   string
	Origin string
	// contains filtered or unexported fields
}

Request has a violated origin policy

func (InvalidOriginPolicy) Error

func (err InvalidOriginPolicy) Error() string

type InvalidRequest

type InvalidRequest struct {
	Field  string
	Reason string
}

invalid request - multiple-value if only 1 expected

func (InvalidRequest) Error

func (err InvalidRequest) Error() string

type Line

type Line struct {
	// contains filtered or unexported fields
}

Line represents the HTTP Request line defined in rfc-2616 : https://tools.ietf.org/html/rfc2616#section-5.1

func (Line) GetURI

func (r Line) GetURI() string

GetURI returns the actual URI

func (*Line) Parse

func (r *Line) Parse(b []byte) error

Parse parses the first HTTP request line

type Method

type Method uint8

Method represents available http methods

const (
	Options Method = iota
	Get
	Head
	Post
	Put
	Delete
)

http methods

type Request

type Request struct {
	// contains filtered or unexported fields
}

Request represents an HTTP Upgrade request

func Parse

func Parse(r io.Reader) (request *Request, err error)

Parse builds an upgrade HTTP request from a reader (typically bufio.NewRead of the socket)

func (*Request) BuildResponse

func (r *Request) BuildResponse() *Response

BuildResponse builds a response from the request

func (Request) GetURI

func (r Request) GetURI() string

GetURI returns the actual URI

func (Request) StatusCode

func (r Request) StatusCode() StatusCode

StatusCode returns the status current

type Response

type Response struct {
	// contains filtered or unexported fields
}

Response represents an HTTP Upgrade Response

func (Response) GetProtocol

func (r Response) GetProtocol() []byte

GetProtocol returns the choosen protocol if set, else nil

func (Response) GetStatusCode

func (r Response) GetStatusCode() StatusCode

GetStatusCode returns the response status code

func (*Response) ProcessKey

func (r *Response) ProcessKey(k []byte)

ProcessKey processes the accept token according to the rfc from the Sec-WebSocket-Key

func (Response) Send

func (r Response) Send(w io.Writer) (int, error)

Send sends the response through an io.Writer typically a socket

func (*Response) SetProtocol

func (r *Response) SetProtocol(p []byte)

SetProtocol sets the protocols

func (*Response) SetStatusCode

func (r *Response) SetStatusCode(sc StatusCode)

SetStatusCode sets the status code

type StatusCode

type StatusCode uint16

StatusCode maps the status codes (and description)

const (
	// SwitchingProtocols - handshake success
	SwitchingProtocols StatusCode = 101
	// BadRequest - missing/malformed headers
	BadRequest StatusCode = 400
	// Forbidden - invalid origin policy, TLS required
	Forbidden StatusCode = 403
	// UpgradeRequired - invalid WS version
	UpgradeRequired StatusCode = 426
	// NotFound - unserved or invalid URI
	NotFound StatusCode = 404
	// Internal - custom error
	Internal StatusCode = 500
)

func (StatusCode) String

func (sc StatusCode) String() string

String implements the Stringer interface

Jump to

Keyboard shortcuts

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