Passenger::Application::Session Class Reference

#include <Application.h>

Inherited by Passenger::Application::StandardSession, and Passenger::ApplicationPoolServer::RemoteSession.

List of all members.


Detailed Description

Represents the life time of a single request/response pair of a Ruby on Rails application.

Session is used to forward a single HTTP request to a Ruby on Rails application. A Session has two communication channels: one for reading data from the RoR application, and one for writing data to the RoR application.

In general, a session object is to be used in the following manner:

  1. Convert the HTTP request headers into a string, as expected by sendHeaders(). Then send that string by calling sendHeaders().
  2. In case of a POST of PUT request, send the HTTP request body by calling sendBodyBlock(), possibly multiple times.
  3. Close the writer channel since you're now done sending data.
  4. The HTTP response can now be read through the reader channel (getReader()).
  5. When the HTTP response has been read, the session must be closed. This is done by destroying the Session object.

A usage example is shown in Application::connect().

Public Member Functions

virtual void sendHeaders (const char *headers, unsigned int size)
 Send HTTP request headers to the RoR application.
virtual void sendHeaders (const string &headers)
 Convenience shortcut for sendHeaders(const char *, unsigned int).
virtual void sendBodyBlock (const char *block, unsigned int size)
 Send a chunk of HTTP request body data to the RoR application.
virtual int getReader () const =0
 Get the reader channel's file descriptor.
virtual void closeReader ()=0
 Close the reader channel.
virtual int getWriter () const =0
 Get the writer channel's file descriptor.
virtual void closeWriter ()=0
 Close the writer channel.
virtual pid_t getPid () const =0
 Get the process ID of the application instance that belongs to this session.


Member Function Documentation

virtual void Passenger::Application::Session::sendHeaders ( const char *  headers,
unsigned int  size 
) [inline, virtual]

Send HTTP request headers to the RoR application.

The HTTP headers must be converted into CGI headers, and then encoded into a string that matches this grammar:

		   headers ::= header*
		   header ::= name NUL value NUL
		   name ::= notnull+
		   value ::= notnull+
		   notnull ::= "\x01" | "\x02" | "\x02" | ... | "\xFF"
		   NUL = "\x00"
		   

This method should be the first one to be called during the lifetime of a Session object. Otherwise strange things may happen.

Parameters:
headers The HTTP request headers, converted into CGI headers and encoded as a string, according to the description.
size The size, in bytes, of headers.
Precondition:
headers != NULL
Exceptions:
IOException The writer channel has already been closed.
SystemException Something went wrong during writing.

virtual void Passenger::Application::Session::sendHeaders ( const string &  headers  )  [inline, virtual]

Convenience shortcut for sendHeaders(const char *, unsigned int).

Parameters:
headers 
Exceptions:
IOException The writer channel has already been closed.
SystemException Something went wrong during writing.

virtual void Passenger::Application::Session::sendBodyBlock ( const char *  block,
unsigned int  size 
) [inline, virtual]

Send a chunk of HTTP request body data to the RoR application.

You can call this method as many times as is required to transfer the entire HTTP request body.

This method should only be called after a sendHeaders(). Otherwise strange things may happen.

Parameters:
block A block of HTTP request body data to send.
size The size, in bytes, of block.
Exceptions:
IOException The writer channel has already been closed.
SystemException Something went wrong during writing.

virtual int Passenger::Application::Session::getReader (  )  const [pure virtual]

Get the reader channel's file descriptor.

Precondition:
The reader channel has not been closed.

virtual void Passenger::Application::Session::closeReader (  )  [pure virtual]

Close the reader channel.

This method may be safely called multiple times.

virtual int Passenger::Application::Session::getWriter (  )  const [pure virtual]

Get the writer channel's file descriptor.

You should rarely have to use this directly. One should only use sendHeaders() and sendBodyBlock() whenever possible.

Precondition:
The writer channel has not been closed.

virtual void Passenger::Application::Session::closeWriter (  )  [pure virtual]

Close the writer channel.

This method may be safely called multiple times.


The documentation for this class was generated from the following file:
Generated on Wed May 7 20:28:19 2008 for Passenger by  doxygen 1.5.3