Virtuoso VSP, HTTP Headers and Cookies

HTTP Response Headers

This posts brings together several related pieces of Virtuoso Server Pages documentation.

First, we’ll handle HTTP Headers. To set a header in VSP, one can use

http_header (string)

However, contrary to intuition, using this command a second time doesn’t set a second header entry, but replaces the last one. To “accumulate” custom headers entries, one must use

http_header ( concat (http_header_get (), string));

Please not that string must end in “\r\n”. http_header.get () returns the currently built up header entries so the line above appends a new entry to the accumulated header entries.

An example from description.vsp of the DBpedia plugin:

  http_header ( concat (http_header_get (), sprintf ('Expires: %s \r\n', date_rfc1123 (dateadd ('day', 7, now ())))));
  http_header ( concat (http_header_get (), 'Set-Cookie: dbpv_has_js=0\r\n'));
This code sets the “Expires” and “Set-Cookie” headers. Notice “\r\n” at the end of both entries.

Accessing HTTP Request Header (for cookies)

To access the HTTP request header in VSP, one can use:

http_request_header ()

To access some entry (“Cookie” for example) in the request header, the following line should be used:

http_request_header (http_request_header (), 'Cookie', null, '');

This line returns all cookie information included in the Request header. To get some value from the cookie, one can use the following:

get_keyword ('cookie_value', split_and_decode (cookie, 0, ';='), '');
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s