-
-
Notifications
You must be signed in to change notification settings - Fork 3
Description
The stpsrv_header() function is used in SAS 9 to alter the http headers sent to the frontend (along with the request body).
Examples from official documentation: https://documentation.sas.com/doc/en/itechcdc/9.4/stpug/srvhead.htm (could be used as test cases)
In sasjs/server we can achieve this by using the fcmp function described here: https://core.sasjs.io/mfs__httpheader_8sas.html
This involves setting a macro variable in the autoexec ( %let sasjs_stpsrv_header_loc=%sysfunc(pathname(work))/../stpsrv_header.txt;) which the location of a text file that is written to the session folder.
If the file exists in the session folder, response headers are set according to the file contents. If the file has duplicates, the last one is used. If the final record has an empty VALUE then the header is removed.
The actual response depends on the way that the request is invoked.
- If GET
/SASjsApi/stp/executethen the actual http response headers are set accordingly - If POST
/SASjsApi/stp/executethen the header table is simply inserted into the JSON response (alongsidelogandwebout), eg:{headers:[{header1:value1},{header2:value2}],log:{},webout:{}}
%let sasjs_stpsrv_header_loc=%sysfunc(pathname(work))/../stpsrv_header.txt;
%mfs_httpheader(Content-type,application/csv)
%mfs_httpheader(Expires,%str(Thu, 18 Nov 1999 12:23:34 GMT))
data _null_;
infile "&sasjs_stpsrv_header_loc";
input;
putlog _infile_;
run;