Barracuda Application Server C/C++ Reference
NO
HttpResRdr Struct Reference

Detailed Description

The HTTP resource reader searches and presents IoIntf resources to HTTP clients requesting such information.

The HttpResRdr class makes it possible for HTTP clients to fetch resources from an IoIntf implementation. The HttpResRdr is a bridge between HTTP request/response and the IoIntf implementation. As an example, the HttpResRdr class can fetch files such as HTML files, gif images, etc from a file system and send the file to a HTTP client requesting the information.

The HttpResRdr can only download files to a client, not upload files to the server; thus, the HttpResRdr is only using the "read" methods in the IoIntf. HTTP Methods supported by HttpResRdr are: OPTIONS, GET, or HEAD. HttpResRdr accepts any HTTP method for include/forward delegations and files not found. This is explained below.

The HttpResRdr searches the IoIntf for the requested resource and automatically handles the response. If the resource cannot be found, HttpResRdr delegates the request to the original HttpDir service function. The HTTP Method type is ignored if the resource is not found. This means that you can insert CSP or HttpDir/HttpPage instances in the HttpResRdr by using HttpDir::insertPage and HttpDir::insertDir.

A client requesting a directory ending with '/' makes the HttpResRdr search for index.X files, where X is 'htm', 'html', and extensions as specified by installed filters. The HttpDir service method returns -1 if no index.X file can be found or the directory does not end with '/'.

The HttpResRdr treats files with extension 'shtml' as hidden files that can only be accessed via HttpResponse::forward or HttpResponse::include.

The HttpResRdr is specifically designed to be used with HttpResponse::include and HttpResponse::forward. The HTTP method is ignored and is assumed to be a GET if the HttpResRdr detects that this is a forward or include call. This makes it possible to design model view controller applications by using HttpResponse::forward from a CSP page or an HttpPage.

Response data is sent with a HTTP size header for direct delegations and HttpResponse::forward delegations. HttpResponse::include delegations require special handling and data is sent using chunk encoding for HTTP 1.1 clients.

The HttpResRdr automatically handles caching and sends a "304 not modified" response to a client if it detects that the client version is the same as the server version. The cache handling defaults to etags and downgrades to time handling if the client does not support etags.

Limitations:
A HttpResRdr instance is normally used for downloading small HTML files, gif images etc, but may also be used for downloading large files. The HttpResRdr instance blocks the current thread when downloading a file and a large file may take considerable time to download. A Barracuda Web-Server running in the default single threaded mode will block all other requests while downloading a large file. It is, therefore, recommended to run the server in multi threaded mode if you use a HttpResRdr instance to download large files. See class HttpCmdThreadPool for more information.

#include <HttpResRdr.h>

Inheritance diagram for HttpResRdr:

Public Member Functions

 HttpResRdr (IoIntf *io, const char *dirName, AllocatorIntf *alloc=0, S8 priority=0)
 Initializes a HttpResRdr. More...
 
 HttpResRdr (IoIntf *io, const char *domain, const char *p404, AllocatorIntf *alloc=0, S8 priority=0)
 Initialize a HttpResRdr for name based virtual hosting. More...
 
int insertPrologDir (HttpDir *dir)
 Insert a prologue HttpDir. More...
 
int installFilter (HttpRdFilter *filter)
 Install a filter. More...
 
void setMaxAge (BaTime maxAge)
 Makes the HttpResRdr instance set the HTTP header "Cache-Control: max-age" for all resources. More...
 
IoIntfgetIo ()
 Returns the IoIntf used by the HttpResRdr.
 
- Public Member Functions inherited from HttpDir
 HttpDir ()
 Constructor for creating a root dir, a root dir has no name.
 
 HttpDir (const char *name, S8 priority=0)
 Constructor for creating a sub-directory. More...
 
int insertDir (HttpDir *dir)
 Insert a sub-directory. More...
 
int insertPage (HttpPage *page)
 Insert a page in the directory. More...
 
HttpPagegetFirstPage ()
 Returns the first page.
 
HttpDirgetFirstDir ()
 Returns the first sub-directory.
 
HttpDirgetDir (const char *name)
 Returns the first directory with the name given or NULL if not found.
 
HttpPagegetPage (const char *name)
 Returns the page with the name given or NULL if not found.
 
HttpDirgetNext ()
 Returns the next dir in the parent list. More...
 
HttpPagefindPage (HttpPage *iter, const char *name)
 Searches for a page in this directory node. More...
 
HttpDircreateOrGet (const char *name)
 Returns a sub-directory with the given name. More...
 
const char * getName () const
 Returns the directory name.
 
HttpDirgetParent () const
 Returns the parent directory or NULL if no parent.
 
char * makeAbsPath (const char *relPath, int relPathLen)
 Makes an absolute path based on where the HttpDir instance is installed in the virtual file system and the provided relative path. More...
 
char * getRootPath ()
 Calculates the root of where the HttpDir instance is installed in the virtual file system. More...
 
HttpDir_Service overloadService (HttpDir_Service s)
 Replace the original service function in HttpDir with your own. More...
 
void p403 (const char *p403)
 Set a 403 denied request handler. More...
 
bool isLinked ()
 Returns true if this directory node is installed into a parent directory.
 
int unlink ()
 Unlinks/removes the directory from the parent directory.
 
void setAuthenticator (struct AuthenticatorIntf *authenticator, struct AuthorizerIntf *authorizer=0)
 Set the optional authenticator and/or the optional AuthorizerIntf. More...
 
bool authenticateAndAuthorize (HttpCommand *cmd, const char *path)
 Authenticate and authorize the user. More...
 

Static Public Member Functions

static void sendFile (IoIntf *io, const char *name, IoStat *st, HttpCommand *cmd)
 Send resource to a client. More...
 
- Static Public Member Functions inherited from HttpDir
static HttpDirfindDir (HttpDir *iter, const char *name, unsigned int nameLen)
 Searches for a sub-directory in this directory node. More...
 

Constructor & Destructor Documentation

◆ HttpResRdr() [1/2]

HttpResRdr::HttpResRdr ( IoIntf io,
const char *  dirName,
AllocatorIntf alloc = 0,
S8  priority = 0 
)

Initializes a HttpResRdr.

Parameters
iois a IoIntf implementation such as ZipIo.
dirNameis the HttpDir name. You must allocate persistent memory for this string if not constant. See HttpDir for an example.
allocis the allocator used for allocating temporary string objects.
priorityis the HttpDir priority.

◆ HttpResRdr() [2/2]

HttpResRdr::HttpResRdr ( IoIntf io,
const char *  domain,
const char *  p404,
AllocatorIntf alloc = 0,
S8  priority = 0 
)

Initialize a HttpResRdr for name based virtual hosting.

A HttpResRdr instance initialized for virtual hosting must be installed as a root directory using method HttpServer::insertRootDir.

The C constructor name is: HttpResRdr_constructor2.

Please note that you must allocate persistent memory for the string 'domain' and 'p404' if not constant. See HttpDir for an example.

Parameters
iois a IoIntf implementation such as ZipIo.
domainis the domain name for this HttpResRdr instance.
p404is the path to a 404 resource. The HttpResRdr instance automatically forwards the request to this resource if the resource requested for this domain was not found. You can set this parameter to NULL, thus making the web-server continue searching for the page in another resource with the same domain or in a resource that accepts any domain. The 404 resource can be a CSP page, an LSP page, a static HTML page, etc..
allocis the allocator used for allocating temporary string objects.
priorityis the HttpDir priority.

Member Function Documentation

◆ insertPrologDir()

int HttpResRdr::insertPrologDir ( HttpDir dir)

Insert a prologue HttpDir.

prologue directories are activated (called) before the HttpResRdr service function is run, but after authentication. The the HttpResRdr service function is not activated if a prologue directory finds the resource. Epilogue directories can be inserted by using method HttpDir::insertDir. prologue and epilogue directories are chained instead of added as sub directories if the directory name for the added directories is NULL. The priorities for sub directories and/or chained directories are: prologue > HttpResRdr > epilogue.

◆ installFilter()

int HttpResRdr::installFilter ( HttpRdFilter filter)

Install a filter.

The HttpRdFilter Documentation is not complete.

◆ sendFile()

void HttpResRdr::sendFile ( IoIntf io,
const char *  name,
IoStat st,
HttpCommand cmd 
)
static

Send resource to a client.

The sendFile method is internally used by the HttpResRdr when sending a resource to a client. The method automatically handles caching and HTTP method type handling as explained above.

The method is made public as it may be useful for specialized HttpDir implementations. The method cannot be used with HttpResponse:include calls or if data is committed. No data can be sent on the response object prior to calling this method.

◆ setMaxAge()

void HttpResRdr::setMaxAge ( BaTime  maxAge)

Makes the HttpResRdr instance set the HTTP header "Cache-Control: max-age" for all resources.

See HttpResponse::setMaxAge for more information.