Returns the value of an HTTP request header.
Syntax
HTTP_HEADER( header-field-name )
Parameters
- header-field-name – The name of an HTTP request header field.
Returns
LONG VARCHAR.
Note:
The result data type is a LONG VARCHAR. If you use HTTP_HEADER in a SELECT INTO statement, you must have an Unstructured Data Analytics Option license or use CAST and set HTTP_HEADER to the correct data type and size.
Remarks
This function returns the value of the named HTTP request header field, or NULL if it does not exist or if it is not called from an HTTP service. It is used when processing an HTTP request via a web service.
Some headers that may be of interest when processing an HTTP web service request include the following:
- Cookie – The cookie value(s), if any, stored by the client, that are associated with the requested URI.
- Referer – The URL of the page (for example, http://documents.sample.com:80/index.html) that contained the link to the requested URI.
- Host – The Internet host name or IP address and port number of the resource being requested, as obtained from the original URI given by the user or referring resource (for example, webserver.sample.com:8082).
- User-Agent – The name of the client application (for example, Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0).
- Accept-Encoding – A list of encodings for the response that are acceptable to the client application (for example, gzip, deflate).
More information about these headers is available at http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html.
The following special headers allow access to the elements within the request line of a client request.
- @HttpMethod – Returns the type of request being processed. Possible values include DELETE, HEAD, GET, PUT, or POST.
- @HttpURI – The full URI of the request, as it was specified in the HTTP request (for example, /myservice?&id=-123&version=109&lang=en).
- @HttpVersion – The HTTP version of the request (for example, HTTP/1.0, or HTTP/1.1).
- @HttpQueryString – Returns the query portion of the requested URI if it exists (for example, id=-123&version=109&lang=en).
Standards and compatibility
- SQL/2008 – Vendor extension.
Example
When used within a stored procedure that is called by an HTTP web service, the following example gets the Cookie header value:
SET cookie_value = HTTP_HEADER( 'Cookie' );
When used within a stored procedure that is called by an HTTP web service, the following example displays the name and values of the HTTP request headers in the database server messages window.
BEGIN
declare header_name long varchar;
declare header_value long varchar;
set header_name = NULL;
header_loop:
LOOP
SET header_name = NEXT_HTTP_HEADER( header_name );
IF header_name IS NULL THEN
LEAVE header_loop
END IF;
SET header_value = HTTP_HEADER( header_name );
MESSAGE 'HEADER: ', header_name, '=',
header_value TO CONSOLE;
END LOOP;
END;