Skip to content

Enable stpsrv_header()  #58

@allanbowe

Description

@allanbowe

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/execute then the actual http response headers are set accordingly
  • If POST /SASjsApi/stp/execute then the header table is simply inserted into the JSON response (alongside log and webout), 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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions