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.

302osi.xml:

<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" />
        </m:message>
    </osi:response>
</osi:http>
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:

httpobjectredirect.obyx:

<instruction xmlns="http://www.obyx.org">
    <output space="http" value="object" />
    <input space="file" value="302osi.xml" />
</instruction>
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.

cookieosi.xml:

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



Last Modified: Thu, 15 Jan 2015