From 61556b2de80aeb0efbd59c90bde30836991ab0a8 Mon Sep 17 00:00:00 2001 From: Allan Bowe Date: Sat, 30 Apr 2022 15:53:59 +0000 Subject: [PATCH 1/3] feat: adding MARKDOWN support to mp_streamfile(), correcting Content-type case issue also --- all.sas | 51 +++++++++++++++++++++++++----------------- base/mp_streamfile.sas | 51 +++++++++++++++++++++++++----------------- 2 files changed, 60 insertions(+), 42 deletions(-) diff --git a/all.sas b/all.sas index 2b5f745..434d93e 100644 --- a/all.sas +++ b/all.sas @@ -11722,8 +11722,10 @@ create table &outds as %mend mp_stprequests;/** @file @brief Streams a file to _webout according to content type - @details Will set headers using appropriate functions (SAS 9 vs Viya) and send - content as a binary stream. + @details Will set headers using appropriate functions per the server type + (Viya, EBI, SASjs Server) and content as a binary stream. + + A co Usage: @@ -11733,7 +11735,14 @@ create table &outds as %mp_streamfile(contenttype=csv,inloc=/some/where.txt,outname=myfile.txt) - @param [in] contenttype= (TEXT) Either TEXT, ZIP, CSV, EXCEL + @param [in] contenttype= (TEXT) Supported: + @li CSV + @li EXCEL + @li MARKDOWN + @li TEXT + @li ZIP + Feel free to submit PRs to support more mime types! The official list is + here: https://www.iana.org/assignments/media-types/media-types.xhtml @param [in] inloc= /path/to/file.ext to be sent @param [in] inref= fileref of file to be sent (if provided, overrides `inloc`) @param [in] iftrue= (1=1) Provide a condition under which to execute. @@ -11779,7 +11788,7 @@ run; %if &contentype=CSV %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; - rc=stpsrv_header('Content-type','application/csv'); + rc=stpsrv_header('Content-Type','application/csv'); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); run; %end; @@ -11789,7 +11798,7 @@ run; contentdisp="attachment; filename=&outname"; %end; %else %if &platform=SASJS %then %do; - %mfs_httpheader(Content-type,application/csv) + %mfs_httpheader(Content-Type,application/csv) %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) %end; %end; @@ -11797,7 +11806,7 @@ run; /* suitable for XLS format */ %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; - rc=stpsrv_header('Content-type','application/vnd.ms-excel'); + rc=stpsrv_header('Content-Type','application/vnd.ms-excel'); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); run; %end; @@ -11807,14 +11816,14 @@ run; contentdisp="attachment; filename=&outname"; %end; %else %if &platform=SASJS %then %do; - %mfs_httpheader(Content-type,application/vnd.ms-excel) + %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) %then %do; data _null_; - rc=stpsrv_header('Content-type',"image/%lowcase(&contenttype)"); + rc=stpsrv_header('Content-Type',"image/%lowcase(&contenttype)"); run; %end; %else %if &platform=SASVIYA %then %do; @@ -11822,30 +11831,30 @@ run; contenttype="image/%lowcase(&contenttype)"; %end; %else %if &platform=SASJS %then %do; - %mfs_httpheader(Content-type,image/%lowcase(&contenttype)) + %mfs_httpheader(Content-Type,image/%lowcase(&contenttype)) %end; %end; -%else %if &contentype=HTML %then %do; +%else %if &contentype=HTML or &contenttype=MARKDOWN %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; - rc=stpsrv_header('Content-type','text/html'); + rc=stpsrv_header('Content-Type',"text/%lowcase(&contenttype)"); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); run; %end; %else %if &platform=SASVIYA %then %do; filename &outref filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json" - contenttype="text/html" + contenttype="text/%lowcase(&contenttype)" contentdisp="attachment; filename=&outname"; %end; %else %if &platform=SASJS %then %do; - %mfs_httpheader(Content-type,text/html) + %mfs_httpheader(Content-Type,text/%lowcase(&contenttype)) %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) %end; %end; %else %if &contentype=TEXT %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; - rc=stpsrv_header('Content-type','application/text'); + rc=stpsrv_header('Content-Type','application/text'); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); run; %end; @@ -11855,14 +11864,14 @@ run; contentdisp="attachment; filename=&outname"; %end; %else %if &platform=SASJS %then %do; - %mfs_httpheader(Content-type,application/text) + %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) %then %do; data _null_; - rc=stpsrv_header('Content-type',"font/%lowcase(&contenttype)"); + rc=stpsrv_header('Content-Type',"font/%lowcase(&contenttype)"); run; %end; %else %if &platform=SASVIYA %then %do; @@ -11870,13 +11879,13 @@ run; contenttype="font/%lowcase(&contenttype)"; %end; %else %if &platform=SASJS %then %do; - %mfs_httpheader(Content-type,font/%lowcase(&contenttype)) + %mfs_httpheader(Content-Type,font/%lowcase(&contenttype)) %end; %end; %else %if &contentype=XLSX %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; - rc=stpsrv_header('Content-type', + rc=stpsrv_header('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); run; @@ -11888,7 +11897,7 @@ run; contentdisp="attachment; filename=&outname"; %end; %else %if &platform=SASJS %then %do; - %mfs_httpheader(Content-type + %mfs_httpheader(Content-Type ,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ) %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) @@ -11897,7 +11906,7 @@ run; %else %if &contentype=ZIP %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; - rc=stpsrv_header('Content-type','application/zip'); + rc=stpsrv_header('Content-Type','application/zip'); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); run; %end; @@ -11907,7 +11916,7 @@ run; contentdisp="attachment; filename=&outname"; %end; %else %if &platform=SASJS %then %do; - %mfs_httpheader(Content-type,application/zip) + %mfs_httpheader(Content-Type,application/zip) %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) %end; %end; diff --git a/base/mp_streamfile.sas b/base/mp_streamfile.sas index d0f8891..84291c0 100644 --- a/base/mp_streamfile.sas +++ b/base/mp_streamfile.sas @@ -1,8 +1,10 @@ /** @file @brief Streams a file to _webout according to content type - @details Will set headers using appropriate functions (SAS 9 vs Viya) and send - content as a binary stream. + @details Will set headers using appropriate functions per the server type + (Viya, EBI, SASjs Server) and content as a binary stream. + + A co Usage: @@ -12,7 +14,14 @@ %mp_streamfile(contenttype=csv,inloc=/some/where.txt,outname=myfile.txt) - @param [in] contenttype= (TEXT) Either TEXT, ZIP, CSV, EXCEL + @param [in] contenttype= (TEXT) Supported: + @li CSV + @li EXCEL + @li MARKDOWN + @li TEXT + @li ZIP + Feel free to submit PRs to support more mime types! The official list is + here: https://www.iana.org/assignments/media-types/media-types.xhtml @param [in] inloc= /path/to/file.ext to be sent @param [in] inref= fileref of file to be sent (if provided, overrides `inloc`) @param [in] iftrue= (1=1) Provide a condition under which to execute. @@ -58,7 +67,7 @@ run; %if &contentype=CSV %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; - rc=stpsrv_header('Content-type','application/csv'); + rc=stpsrv_header('Content-Type','application/csv'); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); run; %end; @@ -68,7 +77,7 @@ run; contentdisp="attachment; filename=&outname"; %end; %else %if &platform=SASJS %then %do; - %mfs_httpheader(Content-type,application/csv) + %mfs_httpheader(Content-Type,application/csv) %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) %end; %end; @@ -76,7 +85,7 @@ run; /* suitable for XLS format */ %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; - rc=stpsrv_header('Content-type','application/vnd.ms-excel'); + rc=stpsrv_header('Content-Type','application/vnd.ms-excel'); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); run; %end; @@ -86,14 +95,14 @@ run; contentdisp="attachment; filename=&outname"; %end; %else %if &platform=SASJS %then %do; - %mfs_httpheader(Content-type,application/vnd.ms-excel) + %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) %then %do; data _null_; - rc=stpsrv_header('Content-type',"image/%lowcase(&contenttype)"); + rc=stpsrv_header('Content-Type',"image/%lowcase(&contenttype)"); run; %end; %else %if &platform=SASVIYA %then %do; @@ -101,30 +110,30 @@ run; contenttype="image/%lowcase(&contenttype)"; %end; %else %if &platform=SASJS %then %do; - %mfs_httpheader(Content-type,image/%lowcase(&contenttype)) + %mfs_httpheader(Content-Type,image/%lowcase(&contenttype)) %end; %end; -%else %if &contentype=HTML %then %do; +%else %if &contentype=HTML or &contenttype=MARKDOWN %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; - rc=stpsrv_header('Content-type','text/html'); + rc=stpsrv_header('Content-Type',"text/%lowcase(&contenttype)"); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); run; %end; %else %if &platform=SASVIYA %then %do; filename &outref filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json" - contenttype="text/html" + contenttype="text/%lowcase(&contenttype)" contentdisp="attachment; filename=&outname"; %end; %else %if &platform=SASJS %then %do; - %mfs_httpheader(Content-type,text/html) + %mfs_httpheader(Content-Type,text/%lowcase(&contenttype)) %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) %end; %end; %else %if &contentype=TEXT %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; - rc=stpsrv_header('Content-type','application/text'); + rc=stpsrv_header('Content-Type','application/text'); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); run; %end; @@ -134,14 +143,14 @@ run; contentdisp="attachment; filename=&outname"; %end; %else %if &platform=SASJS %then %do; - %mfs_httpheader(Content-type,application/text) + %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) %then %do; data _null_; - rc=stpsrv_header('Content-type',"font/%lowcase(&contenttype)"); + rc=stpsrv_header('Content-Type',"font/%lowcase(&contenttype)"); run; %end; %else %if &platform=SASVIYA %then %do; @@ -149,13 +158,13 @@ run; contenttype="font/%lowcase(&contenttype)"; %end; %else %if &platform=SASJS %then %do; - %mfs_httpheader(Content-type,font/%lowcase(&contenttype)) + %mfs_httpheader(Content-Type,font/%lowcase(&contenttype)) %end; %end; %else %if &contentype=XLSX %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; - rc=stpsrv_header('Content-type', + rc=stpsrv_header('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); run; @@ -167,7 +176,7 @@ run; contentdisp="attachment; filename=&outname"; %end; %else %if &platform=SASJS %then %do; - %mfs_httpheader(Content-type + %mfs_httpheader(Content-Type ,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ) %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) @@ -176,7 +185,7 @@ run; %else %if &contentype=ZIP %then %do; %if (&platform=SASMETA and &streamweb=1) %then %do; data _null_; - rc=stpsrv_header('Content-type','application/zip'); + rc=stpsrv_header('Content-Type','application/zip'); rc=stpsrv_header('Content-disposition',"attachment; filename=&outname"); run; %end; @@ -186,7 +195,7 @@ run; contentdisp="attachment; filename=&outname"; %end; %else %if &platform=SASJS %then %do; - %mfs_httpheader(Content-type,application/zip) + %mfs_httpheader(Content-Type,application/zip) %mfs_httpheader(Content-disposition,%str(attachment; filename=&outname)) %end; %end; From 7caca2f139e73d8c3b8e1153a98bfe8b6bbf2ecf Mon Sep 17 00:00:00 2001 From: Allan Bowe Date: Sat, 30 Apr 2022 15:56:36 +0000 Subject: [PATCH 2/3] chore: typo in docs --- all.sas | 2 -- base/mp_streamfile.sas | 2 -- 2 files changed, 4 deletions(-) diff --git a/all.sas b/all.sas index 434d93e..342b786 100644 --- a/all.sas +++ b/all.sas @@ -11725,8 +11725,6 @@ create table &outds as @details Will set headers using appropriate functions per the server type (Viya, EBI, SASjs Server) and content as a binary stream. - A co - Usage: filename mc url diff --git a/base/mp_streamfile.sas b/base/mp_streamfile.sas index 84291c0..27f4f69 100644 --- a/base/mp_streamfile.sas +++ b/base/mp_streamfile.sas @@ -4,8 +4,6 @@ @details Will set headers using appropriate functions per the server type (Viya, EBI, SASjs Server) and content as a binary stream. - A co - Usage: filename mc url From 1e142f042b6f70ea3cc079d1ac5c4e03933e3896 Mon Sep 17 00:00:00 2001 From: Allan Bowe Date: Sat, 30 Apr 2022 15:58:00 +0000 Subject: [PATCH 3/3] chore: improving docs --- all.sas | 3 ++- base/mp_streamfile.sas | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/all.sas b/all.sas index 342b786..6e40080 100644 --- a/all.sas +++ b/all.sas @@ -11723,7 +11723,8 @@ create table &outds as @file @brief Streams a file to _webout according to content type @details Will set headers using appropriate functions per the server type - (Viya, EBI, SASjs Server) and content as a binary stream. + (Viya, EBI, [SASjs Server](https://github.com/sasjs/server)) and stream + content using mp_binarycopy(). Usage: diff --git a/base/mp_streamfile.sas b/base/mp_streamfile.sas index 27f4f69..f660839 100644 --- a/base/mp_streamfile.sas +++ b/base/mp_streamfile.sas @@ -2,7 +2,8 @@ @file @brief Streams a file to _webout according to content type @details Will set headers using appropriate functions per the server type - (Viya, EBI, SASjs Server) and content as a binary stream. + (Viya, EBI, [SASjs Server](https://github.com/sasjs/server)) and stream + content using mp_binarycopy(). Usage: