http

package
v0.0.0-...-3d9cc79 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2018 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

An HTTP server that manages connections and parses HTTP request messages into executable requests

Index

Constants

View Source
const (
	CONNECT = "CONNECT"
	DELETE  = "DELETE"
	GET     = "GET"
	HEAD    = "HEAD"
	OPTIONS = "OPTIONS"
	PATCH   = "PATCH"
	POST    = "POST"
	PUT     = "PUT"
	TRACE   = "TRACE"
)

Request method verbs

View Source
const (
	VERSION_1_1 = "HTTP/1.1"
)

Variables

This section is empty.

Functions

func PercentDecode

func PercentDecode(field string) (decoded string, malformed error)

func TCPServerBuilder

func TCPServerBuilder(host string) *tcpServerBuilder

Builder for TCPServer that defaults to any available port on localhost

Types

type ConnectionHandler

type ConnectionHandler interface {
	Handle(request *bufio.Reader, response io.Writer)
	Routes() []Route
}

func NewConnectionHandler

func NewConnectionHandler(router Router) ConnectionHandler

type DeleteResource

type DeleteResource interface {
	Delete(client io.Writer, message RequestMessage)
}

type GetResource

type GetResource interface {
	Get(client io.Writer, message RequestMessage)
}

type HeadResource

type HeadResource interface {
	Head(client io.Writer, message RequestMessage)
}

type LineRequestParser

type LineRequestParser struct{}

Parses an HTTP request message one line at a time.

func (*LineRequestParser) Parse

func (parser *LineRequestParser) Parse(reader *bufio.Reader) (ok *requestMessage, err Response)

type Method

type Method interface {
	MakeRequest(requested *requestMessage, resource Resource) (request Request, isSupported bool)
}

type OptionsResource

type OptionsResource interface {
	Options(client io.Writer, message RequestMessage)
}

type PatchResource

type PatchResource interface {
	Patch(client io.Writer, message RequestMessage)
}

type PostResource

type PostResource interface {
	Post(client io.Writer, message RequestMessage)
}

type PutResource

type PutResource interface {
	Put(client io.Writer, message RequestMessage)
}

type QueryParameter

type QueryParameter struct {
	Name, Value string
}

type Request

type Request interface {
	Handle(client io.Writer) error
}

type RequestLineRouter

type RequestLineRouter struct {
	Parser RequestParser
	// contains filtered or unexported fields
}

Routes requests based solely upon the first line in the request

func NewRouter

func NewRouter() *RequestLineRouter

func (*RequestLineRouter) AddRoute

func (router *RequestLineRouter) AddRoute(route Route)

func (*RequestLineRouter) LogRequests

func (router *RequestLineRouter) LogRequests(logger RequestLogger)

func (RequestLineRouter) RouteRequest

func (router RequestLineRouter) RouteRequest(reader *bufio.Reader) (ok Request, err Response)

func (*RequestLineRouter) Routes

func (router *RequestLineRouter) Routes() []Route

type RequestLogger

type RequestLogger interface {
	Parsed(message RequestMessage)
}

type RequestMessage

type RequestMessage interface {
	Method() string
	Target() string
	Version() string
	Path() string
	QueryParameters() []QueryParameter

	HeaderLines() []string
	HeaderValues(field string) (values []string)
	Body() []byte

	MakeResourceRequest(resource Resource) Request
}

func NewDeleteMessage

func NewDeleteMessage(path string) RequestMessage

func NewGetMessage

func NewGetMessage(path string) RequestMessage

func NewHeadMessage

func NewHeadMessage(path string) RequestMessage

func NewOptionsMessage

func NewOptionsMessage(targetAsteriskOrPath string) RequestMessage

Creates an OPTIONS request to the specified target, which can either be a path starting with / or an asterisk-form query of the server as a whole (https://tools.ietf.org/html/rfc7230#section-5.3.4).

func NewPatchMessage

func NewPatchMessage(path string) RequestMessage

func NewPostMessage

func NewPostMessage(path string) RequestMessage

func NewPutMessage

func NewPutMessage(path string) RequestMessage

func NewRequestMessage

func NewRequestMessage(method, path string) RequestMessage

func NewTraceMessage

func NewTraceMessage(path string) RequestMessage

type RequestParser

type RequestParser interface {
	Parse(reader *bufio.Reader) (ok *requestMessage, err Response)
}

type Resource

type Resource interface {
	Name() string
}

Handles requests of supported HTTP methods for a resource

type Response

type Response interface {
	WriteTo(client io.Writer) error
	WriteHeader(client io.Writer) error
}

type Route

type Route interface {
	Route(requested RequestMessage) Request
}

type Router

type Router interface {
	RouteRequest(reader *bufio.Reader) (ok Request, err Response)
	Routes() []Route
}

type TCPServer

type TCPServer struct {
	Host           string
	Port           uint16
	MaxConnections uint
	Handler        ConnectionHandler
	// contains filtered or unexported fields
}

func (*TCPServer) Address

func (server *TCPServer) Address() net.Addr

func (*TCPServer) Routes

func (server *TCPServer) Routes() []Route

func (*TCPServer) Shutdown

func (server *TCPServer) Shutdown() error

func (*TCPServer) Start

func (server *TCPServer) Start() error

type UnfinishedPercentEncoding

type UnfinishedPercentEncoding struct {
	EnclosingField string
}

func (UnfinishedPercentEncoding) Error

func (invalid UnfinishedPercentEncoding) Error() string

Jump to

Keyboard shortcuts

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