http://www.w3.org
. Each header record is a single text
line consisting of a name and a value separated by a colon (:). The
following example shows records in an HTTP header:
old = stpsrv_header("Content-type", "text/html; encoding=utf-8"); old = stpsrv_header("Expires", "Wed, 03 Nov 2004 00:00:00 GMT"); old = stpsrv_header("Pragma", "nocache");
Content-type
header record is generated automatically. The value is set based
on the ODS destination that you use in your stored process. The value
is determined by looking up the ODS destination in the file types
section of the SAS registry and, if appropriate, the Windows registry.
If you do not use ODS to generate the output, then Content-type
defaults to text/html
. Use the STPSRV_HEADER
function if you want to override the default value. Override the value
of Content-type
when you want to do any of
the following:
Content-type: text/xml; encoding=utf-8 Content-type: text/plain; encoding=iso-8859-1 Content-type: text/html; encoding=windows-1252
Expires
header record enables you to control how long
a Web client caches the content.
Expires
header record requires that the expiration time be specified in
Greenwich Mean Time (GMT) and in a particular format. A SAS picture
format can be used to create this value. Use PROC FORMAT to create
a custom format as shown in the following example:
proc format; picture httptime (default=29) other='%a, %0d %b %Y %0H:%0M:%0S GMT' (datatype=datetime); run;
/* Expire this page in six hours */ data _null_; exptime = datetime() + '6:00:00't; old = stpsrv_header('Expires', put(exptime - gmtoff(), httptime. )); run;
/* Expire this page at the beginning of next week (Sunday, 00:00 local time) */ data _null_; exptime = intnx('dtweek', datetime(), 1); old = stpsrv_header('Expires', put(exptime - gmtoff(), httptime. )); run;
Location
header record is unlike other header records. It redirects the Web
client immediately to a different URL. Generally all other header
records and content are ignored when this header record is used. Use
this header to redirect the client to another location for special
conditions. For example, a stored process might redirect a client
to a Help URL if an invalid input or other error condition is detected.
For example, the following stored process redirects the Web client
to a static Help page when an error condition is detected:
%macro doSomething;
...
%if error-condition %then %do;
%let old = %sysfunc(stpsrv_header(Status-Code,300));
%let old = %sysfunc(stpsrv_header(Location,
http://myserv.abc.com/myapp/help.html));
%goto end_processing;
%end;
... normal processing ...
%end_processing:
%mend;
%doSomething;
Location
header is not limited to
a static URL. It might be a SAS Stored Process Web Application or
JSP URL, and it might contain parameters. In the preceding example,
the erroneous request, complete with input parameters, can be redirected
to an error handling stored process. The error handling stored process
can examine the input parameters and generate specific error messages
and context-sensitive Help. This is one method to avoid replicating
error handling or Help material across multiple stored processes.
Pragma
header record is used to specify information not formally defined
in the HTTP specification. The most commonly used value is nocache
. This value disables Web client caching of
content for most Web browsers. Some Web browsers require that other
headers be set in order to prevent caching. For example:
Set-Cookie
header record sends a cookie to the Web client to maintain client-side
state. Here is the format:
old = stpsrv_header("Set-Cookie", "CUSTOMER=WILE_E_COYOTE; path=/SASStoredProcess/do; " || "expires=Wed, 06 Nov 2002 23:12:40 GMT");
scan
DATA step function to split the
name/value pairs on the semicolon (;) delimiters. Then split the name/value
pairs on the equal sign (=) delimiter.