What is the HTTP Object?

In a previous post I discussed how to accomplish simple http redirection using Obyx. This works by internally setting the response code and response headers.

The HTTP Object is a special internal Obyx object that allows you to specify custom response headers and response codes. Setting values in the http object override default response codes and headers.

Anatomy of the HTTP Object

The http object is pretty straight forward. Its an XML object that uses two special OSI namespaces: http://www.obyx.org/osi-application-layer and http://www.obyx.org/message namespaces.


<osi:http xmlns:osi="http://www.obyx.org/osi-application-layer">
    <osi:response code="302" reason="Found" >
        <m:message xmlns:m="http://www.obyx.org/message">
            <m:header name="Location" value="http://www.obyx.org" />
Causes a 302 redirect to http://www.obyx.org

The OSI wrapper contains a core 'reponse' element where the code and message are set. This then contains a 'message' and in this example the message contains a single header 'location' whos value determines the location to redirect to. You can add any headers in here you wish.

Using the HTTP Object

In order to use the http object you simply load it into the sepcial http space called object as in the example below:


<instruction xmlns="http://www.obyx.org">
    <output space="http" value="object" />
    <input space="file" value="302osi.xml" />
This loads the osi object from the file 302osi.xml into the 'http' space called 'object'.

Another Example - Settign a cookie

This example shows how you can use the osi response to set a cookie. Notice in this case that the header element has a sub element called 'subhead'. These elements match the standard OSI naming structure.


<osi:http xmlns:osi="http://www.obyx.org/osi-application-layer">
        <m:message xmlns:m="http://www.obyx.org/message">
            <m:header name="Set-Cookie">
                <m:subhead name="oreo" value="chocolate chip"/>
Creates a cookie called 'oreo' with the value 'chocolate chip'

Last Modified: Thu, 15 Jan 2015