► |  | 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:

request-bindings
request-headers
extract-binding/ single
extract-bindings
exists-binding?

Version: 4.1.4
top← prev up next →

##### 2.4.2`` Bindings

(require web-server/http/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.

(request-bindings req)

→

(listof (or/c (cons/c symbol? string?)
(cons/c symbol? bytes?)))

req : request?

Translates the request-bindings/raw of req by interpreting bytes? as string?s, except in the case of binding:file bindings, which are left as is. Ids are then translated into lowercase symbols.

(request-headers req) → (listof (cons/c symbol? string?))
req : request?

Translates the request-headers/raw of req by interpreting bytes? as string?s. Ids are then translated into lowercase symbols.

(extract-binding/single id binds) → string?
id : symbol?
binds : (listof (cons/c symbol? string?))

Returns the single binding associated with id in the a-list binds if there is exactly one binding. Otherwise raises exn:fail.

(extract-bindings id binds) → (listof string?)
id : symbol?
binds : (listof (cons/c symbol? string?))

Returns a list of all the bindings of id in the a-list binds.

(exists-binding? id binds) → boolean?
id : symbol?
binds : (listof (cons/c symbol? string))

Returns #t if binds contains a binding for id. Otherwise, #f.

Here is an example typical of what you will find in many applications:

(define (get-number req)
(string->number
(extract-binding/single
'number
(request-bindings req))))

top← prev up next →