XPath as part of XQuery and XSLT processors is now frequently provided as part of a more complete processing platform, which typically incorporates Web serving capabilities.
XQuery and XSLT have long been recognised as good languages for producing XHTML and HTML from complex data queries, however they are almost completely ignorant of the Web. There are no native mechanisms in XQuery or XSLT to extract information from HTTP Requests when XQuery or XSLT modules are invoked from a Web Server (acting as a server-side scripting language for processing Web requests).
The HTTP Request module provides a set of functions for extracting information from a HTTP Request. The HTTP Request Module aligns with HTTP 1.1 (see [[!HTTP11]]).
The functions and elements discussed in this document are contained in a single
namespace (see [[!XML-NAMES]]) and referenced using an xs:QName.
The namespace prefix used in this document for functions and elements are
solely related to the HTTP Request module is request
.
This document uses the prefix reqerr
to represent the namespace URI http://exquery.org/ns/request/error
, which is the namespace for all HTTP Request Module error codes and messages. This namespace prefix is not predeclared and its use in this document is not normative.
The namespace prefix used for the functions, datatypes and errors can vary, as long as the prefix is bound to the correct URI.
The URIs of the namespaces and the default prefixes associated with them are:
http://exquery.org/ns/request
for functions and elements -- associated with request
.http://exquery.org/ns/request/error
for annotations and functions -- associated with reqerr
.reqerr
prefix is not expected to change from one version of this document to another. The contents of this namespace may be extended to allow additional errors to be returned.
Each function in this module operates on the HTTP Request of a HTTP Context. The HTTP Reqyest is provided to each function by passing another function which returns a model of the context.
By default this module provides a function to access the HTTP Request Context, which returns an XML Document whoose root element is http:request.
The reasons for using function passing to access the HTTP Context include:
Herein where we refer to the HTTP Request, we refer to the HTTP Reqyest that invoked the processing of the module calling the HTTP Request Module function(s).
request:http
() asdocument-node(element(http:request))
Summary: This function returns an XML model of the HTTP Request of the HTTP Context.
Error Conditions: If there is no HTTP Context this function raises an error with the error code reqerr:REDY0001.
Notes: It is expected that an implementation will heavily optimise the use of this function. Suggested optimisations are to at least:
request:method
($request-context as function() as document-node(element(http:request))) asxs:string
Summary: This function returns the Method of the HTTP Request. The returned value SHOULD be a valid HTTP 1.1 Method, which is expressed in upper-case, and is one of the constants "OPTIONS", "GET", "POST", "PUT", "DELETE", "TRACE" or "CONNECT". Implementations are free to return other method names as long as the protocol builds on top of HTTP 1.1.
request:scheme
($request-context as function() as document-node(element(http:request))) asxs:string
Summary: This function returns the Scheme component of the URI of the HTTP Request.
request:hostname
() asxs:string
Summary: This function returns the Hostname fragment of the Authority component of the URI of the HTTP Request.
request:port
() asxs:integer
Summary: This function returns the Port fragment of the Authority component of the URI of the HTTP Request. If the port is not explicitly specified in the URI, then the default port for the HTTP Scheme is returned (i.e. 21 for FTP, 80 for HTTP and 443 for HTTPS).
request:path
() asxs:string
Summary: This function returns the Path component of the URI of the HTTP Request.
request:query
() asxs:string?
Summary: This function returns the Query Component of the HTTP Request URI, if there is no query component then an empty sequence is returned.
request:uri
() asxs:anyURI
Summary: This function returns the URI of the HTTP Request.
Functions that deal with the TCP/IP Connection of the HTTP Request.
request:address
() asxs:string
Summary: This functions returns the IP address of the server.
request:remote-hostname
() asxs:string
Summary: This functions returns the fully qualified hostname of the client or the last proxy that sent the HTTP Request. If the name of the remote host cannot be established, or an implementation chooses not to establish the remote hostname, this method behaves as request:remote-address(), and returns the IP address.
request:remote-address
() asxs:string
Summary: This functions returns the IP address of the client or the last proxy that sent the HTTP Request.
request:remote-port
() asxs:integer
Summary: This functions returns the TCP port of the client socket or the last proxy that sent the HTTP Request.
A HTTP Parameter is defined as either a fragment of the query portion of the HTTP Request URI or the parameter from a submitted HTML Form where the HTTP Request has the Internet Media Type "application/x-www-form-urlencoded".
request:parameter-names
() asxs:string
*
Summary: This function returns a Sequence containing the names of Parameters available from the HTTP Request.
request:parameter
($parameter-name as xs:string) asxs:string
*
Summary: This function returns a Sequence containing the values of the named HTTP Parameter in the HTTP Request. If there is no such parameter in the HTTP Request, then an empty sequence is returned.
request:parameter
($parameter-name as xs:string, $default as xs:string*) asxs:string
*
Summary: This function returns a Sequence containing the values of the named HTTP Parameter in the
HTTP Request. If there is no such parameter in the HTTP Request, then the value specified in
$default
is returned instead.
request:header-names
() asxs:string
+
Summary: This function returns a Sequence containing the names of the HTTP Headers available from the HTTP Request.
request:header
($header-name as xs:string) asxs:string
?
Summary: This function returns the value of the named HTTP Header in the HTTP Request. If there is no such header, then an empty sequence is returned.
request:header
($header-name as xs:string, $default as xs:string) asxs:string
Summary: This function returns the value of the named HTTP Header in the
HTTP Request. If there is no such header, then the value specified in
$default
is returned instead.
request:cookie-names
() asxs:string
*
Summary: This function returns a Sequence containing the names of the Cookies in the HTTP Headers available from the HTTP Request.
request:cookie
($cookie-name as xs:string) asxs:string
?
Summary: This function returns the value of the named Cookie in the HTTP Request. If there is no such cookie, then an empty sequence is returned.
request:cookie
($cookie-name as xs:string, $default as xs:string) asxs:string
Summary: This function returns the value of the named Cookie in the
HTTP Request. If there is no such cookie, then the value specified in
$default
is returned instead.
TODO
If you plan to implement the HTTP Request Module, there is already a set of common abstraction libraries written in Java
which should significantly reduce the ammount of effort involved and avoid re-inventing more wheels. You need
just implement a few interfaces and adapters. For more information see the TODO
Many thanks to: