HTTP Library
The package http
contains an early version of a HTTP library. The library contains both
a basic HTTP client and a HTTP server.
The library was originally developed by: Christoffer Lundell, Erik Bäck Lindström, Filip Wojtulewicz, Fabian Pranke, Joel Gustafsson, Martin Weman
Basic Types
The library is centered around the types http.Request
and http.Response
,
that represent a HTTP request and a HTTP response respectively.
The Request
type has the following members:
-
http.Method method
Method verb.
-
http.Version version
HTTP version used.
-
http.QueryUrl path
Path requested, including URL parameters. The path is absolute if the
host
header was given, otherwise it is relative. The host header is retained in the headers array even if it is duplicated in the url. -
core.Map<core.Str, core.Str> headers
Headers. All keys are lowercased.
-
core.Map<core.Str, core.Str> cookies
Cookies (automatically parsed from headers).
-
http.Status immediateResponse
Response indicated by the parsing logic.
The Response
type has the following members:
-
http.Version version
HTTP version.
-
http.Status status
HTTP status.
-
void header(core.Str key, core.Str val)
Set header.
-
void header(core.io.Buffer key, core.io.Buffer val)
Set header.
-
core.Maybe<core.Str> header(core.Str key)
Get header.
-
core.Array<http.Cookie> cookies
Cookies to send. These are added automatically as headers if present.
-
void contentType(core.Str type)
Explicit set for content-type.
-
init()
Default constructor.
-
init(core.Str)
Create a 200 response that contains text/html.
-
init(core.Str, http.Status)
Create a response with a particular status and an associated message.
In addition, there are three enumerations that encode central concepts within HTTP:
http.Version
enum Version { HTTP_0_9, HTTP_1_0, HTTP_1_1 }
http.Status
encodes HTTP status codes:
enum Status { none = 0, //Informational 1xx Continue = 100, Switching_Protocol = 101, //Successful 2xx OK = 200, Created = 201, Accepted = 202, Non_Authorative_Information = 203, No_Content = 204, Reset_Content = 205, Partial_Content = 206, //Redirectional 3xx Multiple_Choice = 300, Moved_Permanently = 301, Found = 302, See_Other = 303, Not_Modified = 304, Use_Proxy = 305, //306 (Unused), not used anymore Temporary_Redirect = 307, //Client Error 4xx Bad_Request = 400, Unauthorized = 401, Payment_Required = 402, Forbidden = 403, Not_Found = 404, Method_Not_Allowed = 405, Not_Acceptable = 406, Proxy_Authentication_Required = 407, Request_Timeout = 408, Conflict = 409, Gone = 410, Length_Required = 411, Prediction_Failed = 412, Request_Entity_Too_Large = 413, Request_URI_Too_Long = 414, Unsupported_Media_Type = 415, Request_Range_Not_Satisfiable = 416, Expectation_Failed = 417, //Server Error 5xx Internal_Server_Error = 500, Not_Implemented = 501, Bad_Gateway = 502, Service_Unavailable = 503, Gateway_Timeout = 504, HTTP_Version_Not_Supported = 505 }
http.Method
encodes the different HTTP methods that exist:
enum Method { none, OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT, BAD_METHOD }