From 3c026811e96826ac968c5377695164d60044ea48 Mon Sep 17 00:00:00 2001 From: Allan Bowe Date: Wed, 23 Feb 2022 17:01:50 +0000 Subject: [PATCH] feat: adding SASjs server support to mp_streamfile.sas --- all.sas | 46 +++++++++++++++++++++++++++++++++++------- base/mp_streamfile.sas | 46 +++++++++++++++++++++++++++++++++++------- 2 files changed, 78 insertions(+), 14 deletions(-) diff --git a/all.sas b/all.sas index d789111..74ed5b0 100644 --- a/all.sas +++ b/all.sas @@ -11271,6 +11271,7 @@ create table &outds as

SAS Macros

@li mf_getplatform.sas + @li mfs_httpheader.sas @li mp_binarycopy.sas @author Allan Bowe @@ -11304,7 +11305,7 @@ data _null_; run; %if &contentype=CSV %then %do; - %if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do; + %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; rc=stpsrv_header('Content-type','application/csv'); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); @@ -11315,10 +11316,14 @@ run; contenttype='application/csv' contentdisp="attachment; filename=&outname"; %end; + %else %if &platform=SASJS %then %do; + %mfs_httpheader(Content-type,application/csv) + %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) + %end; %end; %else %if &contentype=EXCEL %then %do; /* suitable for XLS format */ - %if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do; + %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; rc=stpsrv_header('Content-type','application/vnd.ms-excel'); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); @@ -11329,9 +11334,13 @@ run; contenttype='application/vnd.ms-excel' contentdisp="attachment; filename=&outname"; %end; + %else %if &platform=SASJS %then %do; + %mfs_httpheader(Content-type,application/vnd.ms-excel) + %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) + %end; %end; %else %if &contentype=GIF or &contentype=JPEG or &contentype=PNG %then %do; - %if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do; + %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; rc=stpsrv_header('Content-type',"image/%lowcase(&contenttype)"); run; @@ -11340,15 +11349,21 @@ run; filename &outref filesrvc parenturi="&SYS_JES_JOB_URI" contenttype="image/%lowcase(&contenttype)"; %end; + %else %if &platform=SASJS %then %do; + %mfs_httpheader(Content-type,image/%lowcase(&contenttype)) + %end; %end; %else %if &contentype=HTML %then %do; %if &platform=SASVIYA %then %do; filename &outref filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json" contenttype="text/html"; %end; + %else %if &platform=SASJS %then %do; + %mfs_httpheader(Content-type,text/html) + %end; %end; %else %if &contentype=TEXT %then %do; - %if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do; + %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; rc=stpsrv_header('Content-type','application/text'); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); @@ -11359,9 +11374,13 @@ run; contenttype='application/text' contentdisp="attachment; filename=&outname"; %end; + %else %if &platform=SASJS %then %do; + %mfs_httpheader(Content-type,application/text) + %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) + %end; %end; %else %if &contentype=WOFF or &contentype=WOFF2 or &contentype=TTF %then %do; - %if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do; + %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; rc=stpsrv_header('Content-type',"font/%lowcase(&contenttype)"); run; @@ -11370,9 +11389,12 @@ run; filename &outref filesrvc parenturi="&SYS_JES_JOB_URI" contenttype="font/%lowcase(&contenttype)"; %end; + %else %if &platform=SASJS %then %do; + %mfs_httpheader(Content-type,font/%lowcase(&contenttype)) + %end; %end; %else %if &contentype=XLSX %then %do; - %if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do; + %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; rc=stpsrv_header('Content-type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); @@ -11385,9 +11407,15 @@ run; 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' contentdisp="attachment; filename=&outname"; %end; + %else %if &platform=SASJS %then %do; + %mfs_httpheader(Content-type + ,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet + ) + %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) + %end; %end; %else %if &contentype=ZIP %then %do; - %if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do; + %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; rc=stpsrv_header('Content-type','application/zip'); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); @@ -11398,6 +11426,10 @@ run; contenttype='application/zip' contentdisp="attachment; filename=&outname"; %end; + %else %if &platform=SASJS %then %do; + %mfs_httpheader(Content-type,application/zip) + %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) + %end; %end; %else %do; %put %str(ERR)OR: Content Type &contenttype NOT SUPPORTED by &sysmacroname!; diff --git a/base/mp_streamfile.sas b/base/mp_streamfile.sas index 2cbfab3..b442415 100644 --- a/base/mp_streamfile.sas +++ b/base/mp_streamfile.sas @@ -22,6 +22,7 @@

SAS Macros

@li mf_getplatform.sas + @li mfs_httpheader.sas @li mp_binarycopy.sas @author Allan Bowe @@ -55,7 +56,7 @@ data _null_; run; %if &contentype=CSV %then %do; - %if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do; + %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; rc=stpsrv_header('Content-type','application/csv'); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); @@ -66,10 +67,14 @@ run; contenttype='application/csv' contentdisp="attachment; filename=&outname"; %end; + %else %if &platform=SASJS %then %do; + %mfs_httpheader(Content-type,application/csv) + %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) + %end; %end; %else %if &contentype=EXCEL %then %do; /* suitable for XLS format */ - %if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do; + %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; rc=stpsrv_header('Content-type','application/vnd.ms-excel'); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); @@ -80,9 +85,13 @@ run; contenttype='application/vnd.ms-excel' contentdisp="attachment; filename=&outname"; %end; + %else %if &platform=SASJS %then %do; + %mfs_httpheader(Content-type,application/vnd.ms-excel) + %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) + %end; %end; %else %if &contentype=GIF or &contentype=JPEG or &contentype=PNG %then %do; - %if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do; + %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; rc=stpsrv_header('Content-type',"image/%lowcase(&contenttype)"); run; @@ -91,15 +100,21 @@ run; filename &outref filesrvc parenturi="&SYS_JES_JOB_URI" contenttype="image/%lowcase(&contenttype)"; %end; + %else %if &platform=SASJS %then %do; + %mfs_httpheader(Content-type,image/%lowcase(&contenttype)) + %end; %end; %else %if &contentype=HTML %then %do; %if &platform=SASVIYA %then %do; filename &outref filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json" contenttype="text/html"; %end; + %else %if &platform=SASJS %then %do; + %mfs_httpheader(Content-type,text/html) + %end; %end; %else %if &contentype=TEXT %then %do; - %if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do; + %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; rc=stpsrv_header('Content-type','application/text'); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); @@ -110,9 +125,13 @@ run; contenttype='application/text' contentdisp="attachment; filename=&outname"; %end; + %else %if &platform=SASJS %then %do; + %mfs_httpheader(Content-type,application/text) + %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) + %end; %end; %else %if &contentype=WOFF or &contentype=WOFF2 or &contentype=TTF %then %do; - %if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do; + %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; rc=stpsrv_header('Content-type',"font/%lowcase(&contenttype)"); run; @@ -121,9 +140,12 @@ run; filename &outref filesrvc parenturi="&SYS_JES_JOB_URI" contenttype="font/%lowcase(&contenttype)"; %end; + %else %if &platform=SASJS %then %do; + %mfs_httpheader(Content-type,font/%lowcase(&contenttype)) + %end; %end; %else %if &contentype=XLSX %then %do; - %if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do; + %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; rc=stpsrv_header('Content-type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); @@ -136,9 +158,15 @@ run; 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' contentdisp="attachment; filename=&outname"; %end; + %else %if &platform=SASJS %then %do; + %mfs_httpheader(Content-type + ,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet + ) + %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) + %end; %end; %else %if &contentype=ZIP %then %do; - %if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do; + %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; rc=stpsrv_header('Content-type','application/zip'); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); @@ -149,6 +177,10 @@ run; contenttype='application/zip' contentdisp="attachment; filename=&outname"; %end; + %else %if &platform=SASJS %then %do; + %mfs_httpheader(Content-type,application/zip) + %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) + %end; %end; %else %do; %put %str(ERR)OR: Content Type &contenttype NOT SUPPORTED by &sysmacroname!;