Net.HTTP

lib/Net/HTTP.gob

HTTP's protocol values: methods, statuses, header fields, URLs, requests, and the bodies and responses that go with them, shared by the HTTP/1 codec, the client and the server. Nothing here opens a connection.

import Net.HTTP (..)
import Net.HTTP.MediaType as MediaType

let r = withHeaders(request(GET, "https://api.example.com/users/1"),
                    field(Accept, MediaType.json))

This module gathers the types, their constructors and the classes, so that one import brings what a program names and matches on. The functions of each type are in that type's own module, imported under its name: Net.HTTP.HeaderName for HeaderName.parse, Net.HTTP.Headers for Headers.get, Net.HTTP.Status for Status.fromCode, and likewise HeaderValue, MediaType, Method, Credentials, Cookie, Token, HTTPURL, Limits and URL. Their names (parse, get, add) would collide with each other's here, and with the Prelude's. The exceptions are request, field and withHeaders, which build a request; newPOST, newPUT, newPATCH and newExtension, which make a method that carries a body; receive, limited, unbounded and trailers, which read an Incoming body; contentLength, host, upgradeRequested and acceptsTrailers, which read the reserved fields of a received request; and body, stream, statusOnly, noContent, notModified, switch and relay, which build a server's response: a program names them as often as it names a method. The server itself is Net.HTTP.Server.

The client is Net.HTTP.Client, imported on its own: it links OpenSSL, which a program that only handles HTTP values has no need of.

The rules come from HTTP's CVEs. Values are validated strictly when they are made, whether a program writes them or they arrive: no CR, LF or NUL in any of them, and nothing repaired. The fields that frame and route a message -- Content-Length, Transfer-Encoding, Host and the rest -- have no name a program can write, because the library writes them.

acceptsTrailers : fun(Request a) -> Bool -- from Net.HTTP.Request.acceptsTrailers
body : [Content a] fun(Net.HTTP.Status.Status, MediaType, a) -> ServerResponse -- from Net.HTTP.ServerResponse.body
contentLength : fun(Request a) -> Option Int -- from Net.HTTP.Request.contentLength
field : [Header a] fun(a, Value a) -> Headers -- from Net.HTTP.Headers.field
host : fun(Request a) -> Option String -- from Net.HTTP.Request.host
limited : fun(Incoming, Int) -> BodyRead -- from Net.HTTP.Incoming.limited
newExtension : [Body a] fun(MethodName, a) -> Method Payload -- from Net.HTTP.Body.newExtension
newPATCH : [Body a] fun(a) -> Method Payload -- from Net.HTTP.Body.newPATCH
newPOST : [Body a] fun(a) -> Method Payload -- from Net.HTTP.Body.newPOST
newPUT : [Body a] fun(a) -> Method Payload -- from Net.HTTP.Body.newPUT
noContent : fun() -> ServerResponse -- from Net.HTTP.ServerResponse.noContent
notModified : fun() -> ServerResponse -- from Net.HTTP.ServerResponse.notModified
receive : [FromHTTP a] fun(Incoming, Int) -> Either a Buffer -- from Net.HTTP.Incoming.receive
relay : fun(Response Incoming) -> ServerResponse -- from Net.HTTP.ServerResponse.relay
request : [Target b] fun(Method a, b) -> ClientRequest a -- from Net.HTTP.Request.request
statusOnly : fun(Net.HTTP.Status.Status) -> ServerResponse -- from Net.HTTP.ServerResponse.statusOnly
stream : fun(Net.HTTP.Status.Status, MediaType, BodyLength, fun(Sink) -> Either SomeError Headers) -> ServerResponse -- from Net.HTTP.ServerResponse.stream
switch : fun(Token, Headers, fun(Duplex) -> Either SomeError Unit) -> ServerResponse -- from Net.HTTP.ServerResponse.switch
trailers : fun(Incoming) -> Option Headers -- from Net.HTTP.Incoming.trailers
unbounded : fun(Incoming) -> BodyRead -- from Net.HTTP.Incoming.unbounded
upgradeRequested : fun(Request a) -> Array Token -- from Net.HTTP.Request.upgradeRequested
withHeaders : [HasHeaders a] fun(a, Headers) -> a -- from Net.HTTP.Headers.withHeaders
Authorization -- from Net.HTTP.Headers.Authorization
BodyLength -- from Net.HTTP.Stream.BodyLength
ClientError -- from Net.HTTP.Error.ClientError
ClientRequest -- from Net.HTTP.Request.ClientRequest
ContentType -- from Net.HTTP.Headers.ContentType
Control -- from Net.HTTP.Request.Control
Duplex -- from Net.HTTP.Duplex.Duplex
HTTPError -- from Net.HTTP.Error.HTTPError
HTTPURL -- from Net.HTTP.HTTPURL.HTTPURL
HeaderError -- from Net.HTTP.Error.HeaderError
Headers -- from Net.HTTP.Headers.Headers
IdempotencyKey -- from Net.HTTP.Headers.IdempotencyKey
Limits -- from Net.HTTP.Limits.Limits
Location -- from Net.HTTP.Headers.Location
Method -- from Net.HTTP.Method.Method
MethodName -- from Net.HTTP.Method.MethodName
Multiplicity -- from Net.HTTP.Headers.Multiplicity
NewCookie -- from Net.HTTP.Cookie.NewCookie
Payload -- from Net.HTTP.Payload.Payload
RedirectRefused -- from Net.HTTP.Error.RedirectRefused
Refusal -- from Net.HTTP.Error.Refusal
Request -- from Net.HTTP.Request.Request
RequestTarget -- from Net.HTTP.Request.RequestTarget
RetryAfter -- from Net.HTTP.Headers.RetryAfter
SetCookie -- from Net.HTTP.Headers.SetCookie
Status -- from Net.HTTP.Status.Status
Stream -- from Net.HTTP.Stream.Stream
Token -- from Net.HTTP.Token.Token
URL -- from URL.URL
URLError -- from URL.URLError
Body -- from Net.HTTP.Body.Body
fun payload : [Body b] fun(b) -> Payload -- from Net.HTTP.Body.payload
fun contentBytes : [Content c] fun(c) -> Buffer -- from Net.HTTP.ServerResponse.contentBytes
FromHTTP -- from Net.HTTP.Error.FromHTTP
fun fromHTTP : [FromHTTP e] fun(HTTPError) -> e -- from Net.HTTP.Error.fromHTTP
HasHeaders -- from Net.HTTP.Headers.HasHeaders
fun headers : [HasHeaders m] fun(m) -> Headers -- from Net.HTTP.Headers.headers
fun setHeaders : [HasHeaders m] fun(m, Headers) -> m -- from Net.HTTP.Headers.setHeaders
fun headerName : [Header h] fun(h) -> HeaderName -- from Net.HTTP.Headers.headerName
fun multiplicity : [Header h] fun(h) -> Multiplicity -- from Net.HTTP.Headers.multiplicity
fun readValue : [Header h] fun(h, HeaderValue) -> Option (Value h) -- from Net.HTTP.Headers.readValue
fun writeValue : [Header h] fun(h, Value h) -> HeaderValue -- from Net.HTTP.Headers.writeValue
Replay -- from Net.HTTP.Body.Replay
fun httpURL : [Target t] fun(t) -> Either URLError HTTPURL -- from Net.HTTP.Request.httpURL
fun toResponse : [ToResponse r] fun(r) -> ServerResponse -- from Net.HTTP.ServerResponse.toResponse