libhttp

package module
v0.0.0-...-2029fad Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsTitle

func AsTitle(key string) string

Types

type Header struct {
	Key, Value string
}

type Request

type Request struct {
	Method string // e.g, GET, POST, PUT, DELETE
	Path   string // e.g, /index.html
	//Headers []struct{Key, Value string} // e.g, Host: eblog.fly.dev
	Headers []Header // e.g, Content-Type: text/html
	Body    string   // e.g, <html><body><h1>Hi</h1></body></html>
}

func NewRequest

func NewRequest(method, path, host, body string) (*Request, error)

func ParseRequest

func ParseRequest(raw string) (r Request, err error)

ParseRequest parses a HTTP request from the given text.

func (*Request) MarshalText

func (r *Request) MarshalText() ([]byte, error)

func (*Request) String

func (r *Request) String() string

func (*Request) WithHeader

func (r *Request) WithHeader(key, value string) *Request

func (*Request) WriteTo

func (r *Request) WriteTo(w io.Writer) (n int64, err error)

Write writes the Request to the given io.Writer.

type Response

type Response struct {
	StatusCode int // e.g, 200
	//  Headers    []struct{Key, Value string} // e.g, Content-Type: text/html
	Headers []Header // e.g, Content-Type: text/html
	Body    string   // e.g, <html><body><h1>Hi</h1></body></html>
}

func NewResponse

func NewResponse(status int, body string) (*Response, error)

func ParseResponse

func ParseResponse(raw string) (resp *Response, err error)

ParseResponse parses the given HTTP/1.1 response string into the Response. It returns an error of the Response is invalid, - not a valid integet - missing status text - invalid status code - invalid headers it doesn't properly handle multi-line headers, headers with multiple values, or html-encoding, etc.zzs

func (*Response) MarshalText

func (resp *Response) MarshalText() ([]byte, error)

func (*Response) String

func (resp *Response) String() string

func (*Response) WithHeader

func (resp *Response) WithHeader(key, value string) *Response

func (*Response) WriteTo

func (resp *Response) WriteTo(w io.Writer) (n int64, err error)

Jump to

Keyboard shortcuts

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