► |  | Web Server: PLT HTTP Server

1 | Running the Web Server
2 | Writing Servlets
3 | Extending the Web Server
4 | Troubleshooting and Tips
5 | Acknowledgements
| Index

► | 2 | Writing Servlets

2.1 | Defining a Servlet
2.2 | APIs
2.3 | Common Contracts
2.4 | HTTP
2.5 | Web Interaction
2.6 | Stateless Web Interaction
2.7 | Web Cells
2.8 | File Boxes
2.9 | Stateless Web Parameters
2.10 | Formlets
2.11 | Templates
2.12 | Continuation Managers

▼ | 2.4 | HTTP

2.4.1 | Requests
2.4.2 | Bindings
2.4.3 | Responses
2.4.4 | Redirect
2.4.5 | Basic Authentication

On this page:

header
headers-assq
headers-assq*
binding
binding: form
binding: file
bindings-assq
request

Version: 4.1.4
top← prev up next →

##### 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.

(struct |  | request | ( | method
|  |  |  | uri
|  |  |  | headers/raw
|  |  |  | bindings/raw
|  |  |  | post-data/raw
|  |  |  | host-ip
|  |  |  | host-port
|  |  |  | client-ip))

method : symbol?
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))]))

top← prev up next →