Skip to content

DevDoc: Processing a request

Ander edited this page Aug 21, 2014 · 1 revision

When an installation of BeeHub receives a request, first the web server deals with it to decide what to do with it. The .htaccess file is configured to:

  1. Serve every file that exists in the document root (/public) 'as is'
  2. Otherwise, pass the request to (/public)/index.php, so that it is handled there (and this is actual BeeHub code processing it, then).

When the request needs to be handled by BeeHub, (/public)/index.php:

  1. assembles all needed dependencies and initialises the BeeHub request handling with the installed configuration (bootstrapping)

This involves creating an instance of DAV_Registry, which in our configuration is set up to be a BeeHub_Registry instance

  1. it authenticates
  2. upon success, begins to build the response

DAV_Request.php will create an appropriate instance of DAV_Request based on the HTTP request method (i.e.: an instance of one of DAV_Request_XXX, such as DAV_Request_GET, DAV_Request_HEAD, etc.)

  1. Finally, index.php will invoke handleRequest() on the DAV_Request_XXX instance. That instance knows how to interpret the user's request, undestands it and processes it to create the adequate response.

Performing the right operation

The DAV_Request_XXX instance first goes through the handleRequest() method in the parent DAV_Request.php:

  1. Check that the resource in the request exists and is visible to the user.

It fetches a proper instance of DAV_Resource from the DAV_Registry (i.e.: an instance of a subclass of BeeHub_Resource such as BeeHub_File, BeeHub_Sponsor, etc.) and makes it available for the request handler.

  1. Check that the HTTP method is valid
  2. Call the handle() method on the DAV_Request_XXX class.

Then, the handle() method:

  1. Can access the resource representation
  2. Streams the proper HTTP headers
  3. Streams the body of the HTTP response
  • Possibly making use of the method_XXX() of the resource, where XXX matches the requested HTTP method. Note however, that other methods of the resource can also be used!
  • And this method_XXX() may look into the request details to decide what kind of answer to give back. For example, the method_GET() of a BeeHub_Directory always gives an HTML page back. And in case that such an HTML must be the response, there is a view resolver method called include_view() in BeeHub_resource.php that introspects on the request and delivers the right HTML by finding and delegating to the corresponding view/beehub_YYY.php.

Clone this wiki locally