Version: 4.1.5
2.14 Stuffers
The
#lang web-server
module language provides serializable continuations.
The serialization functionality is abstracted into stuffers that control how it operates.
You can supply your own (built with these functions) when you write a stateless servlet.
2.14.1 Basic Combinators
A stuffer is essentially an invertible function captured in this structure.
The following should hold:
(out (in x)) = x |
(in (out x)) = x |
Constructs a contract for a stuffer where in has
the contract (-> dom rng) and out has the contract
(-> rng dom).
The identitiy stuffer.
Composes f and g, i.e., applies f then g for in
and g then f for out.
stuffer-compose with arguments swapped.
Creates a stuffer that stuffs with f if c is true on the input
to in. Similarly, applies f during out if it was applied during
in (which is recorded by prepending a byte.)
Applies stuffer-sequence and stuffer-if to successive tails of x.
2.14.2 Serialization
A stuffer that uses serialize and write/bytes and deserialize and read/bytes.
2.14.3 Base64 Encoding
A stuffer that uses base64-encode and base64-decode.
Useful for getting URL-safe bytes.
2.14.4 GZip Compression
A stuffer that uses gzip/bytes and gunzip/bytes.
Warning: You should compose this with base64-stuffer to get URL-safe bytes.
2.14.5 Key/Value Storage
The web-server/stuffers/hash stuffers rely on a key/value store.
The following should hold:
(begin (write k v) (read k)) = v
A store that stores key key’s value in a file located at
It should be easy to use this interface to create store for databases, like SQLite, CouchDB, or BerkeleyDB.
2.14.6 Hash-addressed Storage
Equivalent to (-> bytes? bytes?).
A content-addressed storage stuffer that stores input bytes, input, in store with the key (H input)
and returns the key. Similarly, on out the original bytes are looked up.
Equivalent to (hash-stuffer md5 (dir-store root))
2.14.7 HMAC-SHA1 Signing
Performs a HMAC-SHA1 calculation on db using kb as the key. The result is guaranteed to be 20 bytes.
(You could curry this to use it with hash-stuffer, but there is little value in doing so over md5.)
A stuffer that signs input using HMAC-SHA1 with kb as the key. The result of the stuffer is
the hash prepended to the input data. When the stuffer is run in reverse, it checks if the first 20 bytes are the correct
has for the rest of the data.
Warning: You should compose this with base64-stuffer to get URL-safe bytes.
Warning: Without explicit provision, it is possible for users to modify the continuations they are sent through the other stuffers.
This stuffer allows the servlet to certify that stuffed data was truly generated by the servlet. Therefore, you should use this
if you are not using the hash-stuffers.
Warning: This stuffer does not encrypt the data in anyway, so users can still observe the stuffed values.
2.14.8 Helpers
Determines if stuffing v into the current servlet’s URL would result in a URL that is too big for Internet Explorer.
(IE only supports URLs up to 2048 characters.).
Constructs a stuffer that serializes, then if the URL is too big, compresses (and base64-encodes), if the URL is still too big
then it stores it in an MD5-indexed database rooted at root.
Equivalent to:
Equivalent to: