Published on :
Utility CREATION_INTERNE

Defining HTTP Headers for SASjs/server

This code is also available in: Deutsch Español Français English
Awaiting validation
Attention : This code requires administrator privileges.
The `%mfs_httpheader` macro takes two parameters: `header_name` (the name of the HTTP header to define) and `header_value` (the value of this header). It uses the global variable `sasjs_stpsrv_header_loc` to determine the location of the file in which to write the headers. The process involves allocating a logical filename (`filename`), opening the file in append mode (`fopen` with 'A'), writing the header line (`fput`, `fwrite`), and finally closing (`fclose`) and freeing (`filename`) the file. Error handling mechanisms are integrated to verify the success of file operations. This mechanism allows dynamic configuration of HTTP headers by the SAS© code itself, particularly for GET requests on the SASjs server.
Related macros and files mentioned in the documentation:
  • `mcf_stpsrv_header.sas©` (related macro)
  • ` @code_sas©_json/liblist.json` (documenting a `liblist` macro for listing SAS© libraries)
  • ` @code_sas©/_version.sas©` (utility macro for SAS© version)
  • ` @code_sas©/mm_getdetails.sas©` (macro for extracting metadata attributes and associations)
  • ` @code_sas©/print_macro_parameters.sas©` (macro for printing macro parameters)
  • ` @code_sas©_json/datastep_infile_trick.json` (documenting a data delimitation technique)
  • ` @html/SAS© Help Center_ accessPersonalCaslibs Action.html Help Center_ isAuthorized Action.html` (documentation on the CAS `isAuthorized` action).
Data Analysis

Type : CREATION_INTERNE


The macro does not consume external or internal SAS data (like SASHELP) as a source for its main processing. Its purpose is to create or modify a text file on the file system to influence the behavior of the SASjs server. The source of the header data (name and value) is provided via the macro parameters.

1 Code Block
MACRO mfs_httpheader Data
Explanation :
This code block defines the `%mfs_httpheader` macro. It declares global and local variables necessary for file management. The macro begins by attempting to assign a fileref (`fref`) to the file path specified by the global variable `sasjs_stpsrv_header_loc`. If this operation fails, it returns an error. Then, it opens this file in append mode (`A`) to add content without overwriting existing content. If the open operation fails, an error is also reported. The macro then writes the `header_name: header_value` pair to the file, ensuring that special characters are handled correctly (`%str`). After writing, the file is closed and the fileref is released. These operations use the `%sysfunc` functions with SAS file input/output functions (`filename`, `fopen`, `fput`, `fwrite`, `fclose`).
Copied!
1%macro mfs_httpheader(
2 header_name
3 ,header_value
4)/*/STORE SOURCE*/;
5%global sasjs_stpsrv_header_loc;
6%local fref fid i;
7 
8%IF %sysfunc(filename(fref,&sasjs_stpsrv_header_loc)) ne 0 %THEN %DO;
9 %put &=fref &=sasjs_stpsrv_header_loc;
10 %put %str(ERR)OR: %sysfunc(sysmsg());
11 %return;
12%END;
13 
14%let fid=%sysfunc(fopen(&fref,A));
15 
16%IF &fid=0 %THEN %DO;
17 %put %str(ERR)OR: %sysfunc(sysmsg());
18 %return;
19%END;
20 
21%let rc=%sysfunc(fput(&fid,%str(&header_name): %str(&header_value)));
22%let rc=%sysfunc(fwrite(&fid));
23 
24%let rc=%sysfunc(fclose(&fid));
25%let rc=%sysfunc(filename(&fref));
26 
27%mend mfs_httpheader;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.