mfs_httpheader.sas
Go to the documentation of this file.
1 /**
2  @file
3  @brief Sets the http headers in the SASjs/server response
4  @details For GET requests, SASjs server will use the file generated by this
5  macro for setting the appropriate http headers in the response.
6 
7  It works by writing a file to the session directory, that is then ingested by
8  the server.
9 
10  The location of this file is driven by the global variable
11  `sasjs_stpsrv_header_loc` which is made available in the autoexec.
12 
13  Usage:
14 
15  %mfs_httpheader(Content-Type,application/csv)
16 
17  @param [in] header_name Name of the http header to set
18  @param [in] header_value Value of the http header to set
19 
20  <h4> Related Macros </h4>
21  @li mcf_stpsrv_header.sas
22 
23  @version 9.3
24  @author Allan Bowe
25 
26 **/
27 
28 %macro mfs_httpheader(header_name
29  ,header_value
30 )/*/STORE SOURCE*/;
31 %global sasjs_stpsrv_header_loc;
32 %local fref fid i;
33 
34 %if %sysfunc(filename(fref,&sasjs_stpsrv_header_loc)) ne 0 %then %do;
35  %put &=fref &=sasjs_stpsrv_header_loc;
36  %put %str(ERR)OR: %sysfunc(sysmsg());
37  %return;
38 %end;
39 
40 %let fid=%sysfunc(fopen(&fref,A));
41 
42 %if &fid=0 %then %do;
43  %put %str(ERR)OR: %sysfunc(sysmsg());
44  %return;
45 %end;
46 
47 %let rc=%sysfunc(fput(&fid,%str(&header_name): %str(&header_value)));
48 %let rc=%sysfunc(fwrite(&fid));
49 
50 %let rc=%sysfunc(fclose(&fid));
51 %let rc=%sysfunc(filename(&fref));
52 
53 %mend mfs_httpheader;