Documentation ¶
Index ¶
- Constants
- Variables
- func ClientError(err error) *types.Response
- func GetRequestBody(request *types.Request) io.Reader
- func GetRequestContentLength(request *types.Request) int
- func NewResponseReader(response *types.Response) types.ResponseReader
- func NewServer(ctx context.Context, hostname string, network string, address string, ...) (types.Server, error)
- func ParseRequest(rdr io.Reader) (*types.Request, int, error)
- func ParseResponse(rdr io.Reader) (*types.Response, error)
- func Redirect(url string) *types.Response
- func ServerError(err error) *types.Response
- func Success(mediatype string, body io.Reader) *types.Response
- type Client
Constants ¶
const ( StatusSuccess types.Status = 2 StatusRedirect types.Status = 3 StatusClientError types.Status = 4 StatusServerError types.Status = 5 )
The spartan response types.
const DefaultMaxRedirects int = 2
DefaultMaxRedirects is the number of chained redirects a Client will perform for a single request by default. This can be changed by altering the MaxRedirects field.
Variables ¶
var ( // InvalidRequestLine indicates a malformed first-line of a spartan request. InvalidRequestLine = errors.New("invalid request line") // InvalidRequestLineEnding says that a spartan request's first line wasn't terminated with CRLF. InvalidRequestLineEnding = errors.New("invalid request line ending") )
var ExceededMaxRedirects = errors.New("spartan.Client: exceeded MaxRedirects")
var InvalidResponseHeaderLine = errors.New("Invalid response header line.")
InvalidResponseHeaderLine indicates a malformed spartan response line.
var InvalidResponseLineEnding = errors.New("Invalid response line ending.")
InvalidResponseLineEnding indicates that a spartan response header didn't end with "\r\n".
var ServerProtocol types.ServerProtocol = proto{}
Functions ¶
func ClientError ¶
ClientError builds a "client error" spartan response.
func GetRequestBody ¶
GetRequestBody returns a reader of the spartan request body.
It will return nil if the request has no body.
func GetRequestContentLength ¶
GetRequestContentLength reads the remaining un-read number of bytes in a request body.
It will immediately return 0 if there is no request body.
func NewResponseReader ¶
func NewResponseReader(response *types.Response) types.ResponseReader
NewResponseReader builds a reader for a response.
func NewServer ¶
func NewServer( ctx context.Context, hostname string, network string, address string, handler types.Handler, baseLog logging.Logger, ) (types.Server, error)
NewServer builds a spartan server.
func ParseRequest ¶
ParseRequest parses a single spartan request and the indicated content-length from a reader.
If ther reader artument is a *bufio.Reader, it will only read a single line from it.
func ServerError ¶
ServerError builds a "server error" spartan response.
Types ¶
type Client ¶
type Client struct {
MaxRedirects int
}
Client is used for sending spartan requests and receiving responses.
It carries no state and is reusable simultaneously by multiple goroutines.
The zero value is immediately usabble, but will not follow redirects.
func NewClient ¶ added in v1.1.0
func NewClient() Client
NewClient creates a spartan Client which will follow DefaultMaxRedirects.
func (Client) Fetch ¶ added in v1.1.0
Fetch parses a URL string and fetches the spartan resource.
It will resolve any redirects along the way, up to client.MaxRedirects.