Chapter 8. Web Variables

Variables directly submitted by the client are parsed into hashes of { name => [ multiple, values ] } :

These hashes are merged together into Web::request, which also is a hash of { name => [ multiple, values ] }. Web[param] is a convenience method to return single values.

File uploads are parsed into Web::Upload objects, with the following methods:

Web::Upload#content_type
The browser-submitted content-type of the upload.
Web::Upload#local_path
The path to the tempfile containing the upload.
Web::Upload#open { |f| ... }
Yields the tempfile IO object, with the pointer at the beginning of the file
Web::Upload#original_filename
The browser-submitted filename of the upload.
Web::Upload#read
Returns the contents of the upload
Web::Upload#save(some_path)
Saves the contents of the tempfile to some_path

Environment variables are copied into a case-insensitive, duck-typing hash (eg Web::env[:script_name])

Reference

Web[key]
Convenience method to access values within Web::request. If the key is array-style, aka 'param[]', the value is returned as an array. Otherwise, value is joined with "," and returned as a string. If Web::request[key] is an array of Web::Upload objects, then the first value of the array is returned.
Web[key] = value
Convenience method to set values within Web::request. If value is not an array, sets key to [value].
Web::cookie
Access cookies sent by the client.
Web::env
ENV variables, scoped to the request, returned in a case-insensitive hash
Web::get
Access parameters passed on the url.
Web::info
Display information about the execution enviroment to the client.
Web::key?(key)
Test whether Web::cookie, Web::get, or Web::post contain the given key.
Web::keys
Return set of the keys of Web::cookie, Web::get, and Web::post.
Web::local
A hash scoped to the current web connection. Similar to Request scope in the Java Servlet API.
Web::post
Access parameters submitted via a form posting.
Web::request
Convenience array. Combines Web::get, Web::post, and Web::cookie into one hash. If the same key is passed in Web::get and Web::post, Web::env['request_method'] is used to choose which takes priority.
Web::raw_post_data
An IO object containing the raw post data from the request.
Web::session
Session values.