exception to wait for writing by EAGAIN. see IO.select
.
exception to wait for writing by EWOULDBLOCK. see IO.select
.
exception to wait for writing by EINPROGRESS. see IO.select
.
This file provides the CGI::Session
class, which provides session support for CGI
scripts. A session is a sequence of HTTP requests and responses linked together and associated with a single client. Information associated with the session is stored on the server between requests. A session id is passed between client and server with every request and response, transparently to the user. This adds state information to the otherwise stateless HTTP request/response protocol.
A CGI::Session
instance is created from a CGI
object. By default, this CGI::Session
instance will start a new session if none currently exists, or continue the current session for this client if one does exist. The new_session
option can be used to either always or never create a new session. See new() for more details.
delete()
deletes a session from session storage. It does not however remove the session id from the client. If the client makes another request with the same id, the effect will be to start a new session with the old session’s id.
The Session
class associates data with a session as key-value pairs. This data can be set and retrieved by indexing the Session
instance using ‘[]’, much the same as hashes (although other hash methods are not supported).
When session processing has been completed for a request, the session should be closed using the close() method. This will store the session’s state to persistent storage. If you want to store the session’s state to persistent storage without finishing session processing for this request, call the update() method.
The caller can specify what form of storage to use for the session’s data with the database_manager
option to CGI::Session::new
. The following storage classes are provided as part of the standard library:
CGI::Session::FileStore
stores data as plain text in a flat file. Only works with String
data. This is the default storage type.
CGI::Session::MemoryStore
stores data in an in-memory hash. The data only persists for as long as the current Ruby interpreter instance does.
CGI::Session::PStore
stores data in Marshalled format. Provided by cgi/session/pstore.rb. Supports data of any type, and provides file-locking and transaction support.
Custom storage types can also be created by defining a class with the following methods:
new(session, options) restore # returns hash of session data. update close delete
Changing storage type mid-session does not work. Note in particular that by default the FileStore
and PStore
session data files have the same name. If your application switches from one to the other without making sure that filenames will be different and clients still have old sessions lying around in cookies, then things will break nastily!
Most session state is maintained on the server. However, a session id must be passed backwards and forwards between client and server to maintain a reference to this session state.
The simplest way to do this is via cookies. The CGI::Session
class provides transparent support for session id communication via cookies if the client has cookies enabled.
If the client has cookies disabled, the session id must be included as a parameter of all requests sent by the client to the server. The CGI::Session
class in conjunction with the CGI
class will transparently add the session id as a hidden input field to all forms generated using the CGI#form() HTML generation method. No built-in support is provided for other mechanisms, such as URL re-writing. The caller is responsible for extracting the session id from the session_id
attribute and manually encoding it in URLs and adding it as a hidden input to HTML forms created by other mechanisms. Also, session expiry is not automatically handled.
require 'cgi' require 'cgi/session' require 'cgi/session/pstore' # provides CGI::Session::PStore cgi = CGI.new("html4") session = CGI::Session.new(cgi, 'database_manager' => CGI::Session::PStore, # use PStore 'session_key' => '_rb_sess_id', # custom session key 'session_expires' => Time.now + 30 * 60, # 30 minute timeout 'prefix' => 'pstore_sid_') # PStore option if cgi.has_key?('user_name') and cgi['user_name'] != '' # coerce to String: cgi[] returns the # string-like CGI::QueryExtension::Value session['user_name'] = cgi['user_name'].to_s elsif !session['user_name'] session['user_name'] = "guest" end session.close
require 'cgi' require 'cgi/session' cgi = CGI.new("html4") # We make sure to delete an old session if one exists, # not just to free resources, but to prevent the session # from being maliciously hijacked later on. begin session = CGI::Session.new(cgi, 'new_session' => false) session.delete rescue ArgumentError # if no old session end session = CGI::Session.new(cgi, 'new_session' => true) session.close
Note: Don’t use this class directly. This is an internal class.
Note: Don’t use this class directly. This is an internal class.
Response class for Multi-Status (WebDAV)
responses (status code 207).
The Multi-Status (WebDAV)
response indicates that the server has received the request, and that the message body can contain a number of separate response codes. See 207 Multi-Status (WebDAV).
Response class for Already Reported (WebDAV)
responses (status code 208).
The Already Reported (WebDAV)
response indicates that the server has received the request, and that the members of a DAV binding have already been enumerated in a preceding part of the (multi-status) response, and are not being included again. See 208 Already Reported (WebDAV).
Response class for Multiple Choices
responses (status code 300).
The Multiple Choices
response indicates that the server offers multiple options for the resource from which the client may choose. See 300 Multiple Choices.
Response class for Multiple Choices
responses (status code 300).
The Multiple Choices
response indicates that the server offers multiple options for the resource from which the client may choose. See 300 Multiple Choices.
Response class for Request Timeout
responses (status code 408).
The server timed out waiting for the request. See 408 Request Timeout.
Response class for Request Timeout
responses (status code 408).
The server timed out waiting for the request. See 408 Request Timeout.
Response class for Payload Too Large
responses (status code 413).
The request is larger than the server is willing or able to process. See 413 Payload Too Large.
Response class for URI Too Long
responses (status code 414).
The URI
provided was too long for the server to process. See 414 URI Too Long.
Response class for URI Too Long
responses (status code 414).
The URI
provided was too long for the server to process. See 414 URI Too Long.
Response class for URI Too Long
responses (status code 414).
The URI
provided was too long for the server to process. See 414 URI Too Long.
Response class for Range Not Satisfiable
responses (status code 416).
The request entity has a media type which the server or resource does not support. See 416 Range Not Satisfiable.
Response class for Range Not Satisfiable
responses (status code 416).
The request entity has a media type which the server or resource does not support. See 416 Range Not Satisfiable.
Response class for Not Implemented
responses (status code 501).
The server either does not recognize the request method, or it lacks the ability to fulfil the request. See 501 Not Implemented.
Response class for Gateway Timeout
responses (status code 504).
The server was acting as a gateway or proxy and did not receive a timely response from the upstream server. See 504 Gateway Timeout.
Response class for Gateway Timeout
responses (status code 504).
The server was acting as a gateway or proxy and did not receive a timely response from the upstream server. See 504 Gateway Timeout.
OpenTimeout
, a subclass of Timeout::Error
, is raised if a connection cannot be created within the open_timeout.
ReadTimeout
, a subclass of Timeout::Error
, is raised if a chunk of the response cannot be read within the read_timeout.
Hash
with completion search feature. See OptionParser::Completion
.