minihttp

package module
v0.0.0-...-e3ed4b4 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

README

minihttp

A Go implementation of a subset of HTTP

Usage

Build
make demo
Testing
make test
Benchmarking
make benchmark

Documentation

Index

Constants

View Source
const (
	// status code and text
	StatusOK     = 200
	StatusOKText = "OK"

	StatusMovedPermanently     = 301
	StatusMovedPermanentlyText = "Moved permanently"

	StatusBadRequest     = 400
	StatusBadRequestText = "Bad request"

	StatusNotFound     = 404
	StatusNotFoundText = "Not found"

	StatusInternalServerError     = 500
	StatusInternalServerErrorText = "Internal Server Error"

	// receive buffer size
	RecvBufSize = 1024

	// receive timeout
	RecvTimeout time.Duration = 5 * time.Second
)

Variables

This section is empty.

Functions

func DirIndexHTML

func DirIndexHTML(basePath, title string) (string, error)

DirIndexHTML() lists the files and directories contained in the given directory, returns a generated html string.

Types

type InvalidRequestError

type InvalidRequestError struct {
	Method      string
	URL         string
	Description string
}

func (*InvalidRequestError) Error

func (e *InvalidRequestError) Error() string

type Request

type Request struct {
	Method string
	URL    string
	Proto  string

	Host    string
	Close   bool
	Headers map[string]string
	Body    string
}

func (*Request) Parse

func (req *Request) Parse(reqString string) error

type Response

type Response struct {
	Proto      string
	StatusCode int
	StatusText string
	Headers    map[string]string
	Body       string
}

func ResponseBadRequest

func ResponseBadRequest(proto string) *Response

400 Bad Request

func ResponseInternalServerError

func ResponseInternalServerError(proto string) *Response

500 Internal Server Error

func ResponseMovedPermanently

func ResponseMovedPermanently(proto, location string, close bool) *Response

301 Moved Permanently

func ResponseNotFound

func ResponseNotFound(proto string, close bool) *Response

404 Not Found

func (*Response) String

func (resp *Response) String() string

type Server

type Server struct {
	// Addr specifies the TCP address for the server to listen on,
	// in the form "host:port". It shall be passed to net.Listen()
	// during ListenAndServe().
	Addr string // e.g. ":0"

	// VirtualHosts contains a mapping from host name to the docRoot path
	// (i.e. the path to the directory to serve static files from) for
	// all virtual hosts that this server supports
	VirtualHosts map[string]string
}

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe listens on the TCP network address s.Addr and then handles requests on incoming connections.

Directories

Path Synopsis
cmd
demo command

Jump to

Keyboard shortcuts

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