4 HTTP: Hypertext Transfer Protocol
The Web Server implements many HTTP libraries that are provided by this module.
4.1 Requests
Represents a header of field to value.
Returns the header with a field equal to id from heads or #f.
Returns the header with a field case-insensitively equal to id from heads or #f.
You almost
always want to use this, rather than
headers-assq because Web browsers may send headers with arbitrary casing.
Represents a binding of id.
Represents a form binding of id to value.
Represents the uploading of the file filename with the id id
and the content content, where headers are the additional headers from
the MIME envelope the file was in. (For example, the #"Content-Type" header may
be included by some browsers.)
Returns the binding with an id equal to id from binds or #f.
Like
bindings-assq, but returns a list of all bindings matching
id.
An HTTP method request to uri from client-ip
to the server at host-ip:host-port with headers/raw
headers, bindings/raw GET and POST queries and post-data/raw
POST data.
You are unlikely to need to construct a request struct.
Here is an example typical of what you will find in many applications:
4.2 Bindings
These functions, while convenient, could introduce subtle bugs into your
application. Examples: that they are case-insensitive could introduce
a bug; if the data submitted is not in UTF-8 format, then the conversion
to a string will fail; if an attacker submits a form field as if it were
a file, when it is not, then the
request-bindings will hold a
bytes? object and your program will error; and, for file uploads
you lose the filename.
Therefore, we recommend against their use, but
they are provided for compatibility with old code.Returns the single binding associated with
id in the a-list
binds
if there is exactly one binding. Otherwise raises
exn:fail.
Returns a list of all the bindings of id in the a-list binds.
Returns #t if binds contains a binding for id.
Otherwise, #f.
Here is an example typical of what you will find in many applications:
4.3 Responses
An HTTP response where output produces the body. code is the response code,
message the message, seconds the generation time, mime
the MIME type of the file, and headers are the headers. If headers does not include Date, Last-Modified, Server, or Content-Type headers, then the server will automatically add them. The server will always replace your Connection header if it needs to ensure the connection will be closed. (Typically with an HTTP/1.0 client.)
A constructor for responses where body is the response body.
Equivalent to #"text/html; charset=utf-8".
Warning: If you include a Content-Length header in a response that is inaccurate, there will be an error in
transmission that the server will not catch.
4.4 Placing Cookies
This module provides functions to create cookies and responses that set them.
Constructs a cookie with the appropriate fields.
Constructs a header that sets the cookie.
Warning: When using cookies, make sure you follow the advice of the
MIT Cookie Eaters,
or you will be susceptible to dangerous attacks.
4.5 Extracting Cookies
While server cookies are represented with
cookie?s, cookies
that come from the client are represented with a
client-cookie structure.
Extracts the cookies from req’s headers.
4.6 Redirect
Generates an HTTP response that redirects the browser to uri,
while including the headers in the response.
Determines if v is one of the following values.
4.7 Basic Authentication
An implementation of HTTP Basic Authentication.
Returns a header that instructs the Web browser to request a username and password from the client using
Basic authentication with realm as the realm.
Returns a pair of the username and password from the authentication
header in req if they are present, or #f.
4.8 Digest Authentication
An implementation of HTTP Digest Authentication.
Returns a header that instructs the Web browser to request a username and password from the client
using Digest authentication with realm as the realm, private-key as the server’s
contribution to the nonce, and opaque as the opaque data passed through the client.
Returns the Digest credentials from req (if they appear) as an association list.
Used to look up the password for a user is a realm.
Used to compute the user’s secret hash.
Uses lookup-password to find the password, then computes the
secret hash of it.
Constructs a function that checks whether particular Digest credentials
(the second argument of the returned function) are correct given the
HTTP method provided as the first argument and the secret hash computed
by lookup-HA1.
This is will result in an exception if the Digest credentials are
missing portions.
4.9 X-expression Support
Equivalent to
This is a viable function to pass to set-any->response!.