http11
(require http11) | package: http11 |
1 HTTP Data Structures
Performs synchronous HTTP 1.1 invocations against a server. Full HTTP 1.1 support is not yet in place. The current incarnation supports gzip compression, SSL and chunk encoding.
struct
(struct RequestLine (method path version) #:transparent) method : Method path : String version : Version
struct
(struct RequestHeader (request headers) #:transparent) request : RequestLine headers : (Listof Header)
struct
(struct StatusLine (version code msg) #:transparent) version : Version code : Integer msg : String
struct
(struct ResponseHeader (status headers) #:transparent) status : StatusLine headers : (Listof Header)
struct
(struct HTTPConnection (header out in real-in) #:transparent) header : ResponseHeader out : Output-Port in : Input-Port real-in : (Option Input-Port)
For example, if the HTTP request has Accept-Encoding: gzip in the request header the server response payload at the "real-in" socket port is gzip compressed. The client application reading reading from "in" port receives a gzip uncommpressed stream of data as this library automatically inserts unzipping pipe between the "real-in" port and the client used "HTTPConnection" "in" port.
Similarly for HTTP chunked encoding. This library automatically inserts a "pipe" between the "HTTPConnection" "real-in" port and the client application reads from the "de-chunked" "HTTPConnection" "in" port.
struct
(struct HTTPPayload (mime md5 length inport) #:transparent) mime : String md5 : (Option String) length : (Option Index) inport : Input-Port
If the "length" is provided the HTTP request sends this value as a Content-Length HTTP header. If the Content-Length is not provided the HTTPClient library uses Transfer-Encoding: chunked in the request.
Chunked encoding allows a client to send a payload of unknown size to the server (or from the server to the client) by buffering a streamed payload as chunks of data.
The mime type string specifies the format of the request payload, e.g., application/json or application/atom+xml.
2 Invoking An HTTP Request
The various HTTP actions or methods are defined as a data type.
value
: (U 'GET 'PUT 'POST 'DELETE 'HEAD 'CONNECT 'OPTIONS 'TRACE)
procedure
(http-invoke method url headers payload) → HTTPConnection
method : Method url : Uri headers : Headers payload : (Option Payload)
There are several utility functions to quickly check the server’s response. The full server response is available in "ResponseHeader" contained in the "HTTPConnection".
procedure
(http-successful? connection) → Boolean
connection : HTTPConnection
procedure
(http-status-code connection) → Integer
connection : HTTPConnection
procedure
(http-has-content? connection) → Boolean
connection : HTTPConnection
procedure
(http-close-connection connection) → Void
connection : HTTPConnection
3 Headers
Headers are name value pairs defined in the HTTP 1.1 specification.
(require http11/header) | package: http11 |
procedure
value : String
procedure
value : String
procedure
value : String
procedure
value : String
procedure
value : String
procedure
value : String
4 Encoding
4.1 URL Encoding / Decoding
procedure
str : String delim : (Option Char) decode-plus? : Boolean
procedure
(url-decode-from-input-port str delim decode-plus?) → String str : String delim : (Option Char) decode-plus? : Boolean