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, ';='), '');

DBPV Prototype

In the following video, you can see the prototype version of the DBpedia Viewer:

To test it out, please take a look at the github repositories of the project:

Please note that the real version may lag behind the toy version during development as changes are propagated from the toy to the real thing.