2.4.1 Requests
(require web-server/http/request-structs) |
(struct header (field value)) |
field : bytes? |
value : bytes? |
Represents a header of field to value.
(headers-assq id heads) → (or/c false/c header?) |
id : bytes? |
heads : (listof header?) |
Returns the header with a field equal to id from heads or #f.
(headers-assq* id heads) → (or/c false/c header?) |
id : bytes? |
heads : (listof header?) |
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.
(struct binding (id)) |
id : bytes? |
Represents a binding of id.
(struct (binding:form binding) (value)) |
value : bytes? |
Represents a form binding of id to value.
(struct (binding:file binding) (filename headers content)) |
filename : bytes? |
headers : (listof header?) |
content : bytes? |
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.)
(bindings-assq id binds) → (or/c false/c binding?) |
id : bytes? |
binds : (listof binding?) |
Returns the binding with an id equal to id from binds or #f.
| ||||||||||||||||||||||||||||||||||||||||
method : bytes? | ||||||||||||||||||||||||||||||||||||||||
uri : url? | ||||||||||||||||||||||||||||||||||||||||
headers/raw : (listof header?) | ||||||||||||||||||||||||||||||||||||||||
bindings/raw : (listof binding?) | ||||||||||||||||||||||||||||||||||||||||
post-data/raw : (or/c false/c bytes?) | ||||||||||||||||||||||||||||||||||||||||
host-ip : string? | ||||||||||||||||||||||||||||||||||||||||
host-port : number? | ||||||||||||||||||||||||||||||||||||||||
client-ip : string? |
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:
(define (get-number req) |
(match |
(bindings-assq |
#"number" |
(request-bindings/raw req)) |
[(? binding:form? b) |
(string->number |
(bytes->string/utf-8 |
(binding:form-value b)))] |
[_ |
(get-number (request-number))])) |