Skip to content

Commit

Permalink
Pass query and headers to application initialisation function
Browse files Browse the repository at this point in the history
  • Loading branch information
mkromberg committed Sep 9, 2024
1 parent 617941f commit 387bcee
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 6 deletions.
6 changes: 5 additions & 1 deletion EWC/Handler.aplf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rcon Handler payload;ns;Event;ID;Info;events;fns;fn;event;reqfn;info;sns;i;code;conn;coni;sock;z;m;msg;sessionspace;form;hr;CALLER;app;new;old;token;TID
rcon Handler payload;ns;Event;ID;Info;events;fns;fn;event;reqfn;info;sns;i;code;conn;coni;sock;z;m;msg;sessionspace;form;hr;CALLER;app;new;old;token;TID;URL
⎕TRAP0 'S'
'R'Log'#',(con),': ',payload
i(2SESSIONS)con
Expand All @@ -19,11 +19,15 @@
:AndIf 0ns{0:: (⎕JSON ).Initialise}payload
:If 2=ns.⎕NC 'Version' CLIENTVERSIONns.Version :EndIf
:If 2=ns.⎕NC 'Function' fnreqfnns.Function :Else fn'' :EndIf
:If 2=ns.⎕NC 'URL' URLns.URL :Else URL'' :EndIf
:Else
fnreqfn(10payload)~'()'
:EndIf
fn,(0=fn)/'Initialise'
appcode
app._EWC.URLURL
app._EWC.QUERYParseQueryString (URL'?')URL
app._EWC.HDRSWSS.Conx[(¯8¨WSS.Conx[;1]),'ZI8' ⎕FMT con;2]
:If 0app.⎕NC 'workNamespace' /// change this name in DWI
appapp.workNamespace
:EndIf
Expand Down
8 changes: 8 additions & 0 deletions EWC/ParseQueryString.aplf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
paramsParseQueryString query
params0 2''
00query
:If '='query contains name=value?
paramsURLDecode¨2[2]'='()¨'&'()query
:Else
paramsURLDecode query
:EndIf
18 changes: 18 additions & 0 deletions EWC/URLDecode.aplf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
rURLDecode r;rgx;rgxu;i;j;z;t;m;⎕IO;lens;fill
:Access public shared
Decode a Percent Encoded string https://en.wikipedia.org/wiki/Percent-encoding
⎕IO0
((r='+')/r)' '
rgx'[0-9a-fA-F]'
rgxu'%[uU]',(4×rgx)rgx 4 characters
r(rgxu ⎕R{{⎕UCS 1616|'0123456789ABCDEF0123456789abcdef'}2.Match})r
:If 0i(r='%')/r
:AndIf 0i(i¯2+r)/i
zr[ji.+1 2]
t'UTF-8'⎕UCS 1616|'0123456789ABCDEF0123456789abcdef'z
lens¨'UTF-8'⎕UCS¨t UTF-8 is variable length encoding
filli[¯1+\0,lens]
r[fill]t
m(r)1 m[(,j),i~fill]0
rm/r
:EndIf
5 changes: 3 additions & 2 deletions EWC/wss.aplc
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
:Leave
:EndIf
hdrsParseHeaders data
Conxobj(hdrs GetHeader'sec-websocket-key')
Conxobj hdrs

:Case 'WSReceive'
:If 0evt RunHandler wres
Expand Down Expand Up @@ -198,10 +198,11 @@


obj Serve data;method;url;httpver;headers;file;respheaders;rc;msg;status;payload;close;ind;i
serve HTML content
serve HTML content
(method url httpver headers)data
respheaders1 2'Server'(deb2Version)
respheaders'Date'(2LDRC.GetProp'.' 'HttpDate')
url(¯1+url'?')url Ignore queries
:If method⎕C'get'
:If '/',url
urlDefaultPage
Expand Down
7 changes: 6 additions & 1 deletion demo/CBRunDemo.aplf
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
CBRunDemo args;e;scores;cols;fcol;pass;ii;ids;target;demo;sf;f;name
{presel} CBRunDemo args;e;scores;cols;fcol;pass;ii;ids;target;demo;sf;f;name
:If 2=⎕NC 'presel'
RUN demopresel
:EndIf

Event⎕NS''
eEvent.Event⎕NS''
e.(ID EventName Info)(2args),2args
Expand All @@ -23,6 +27,7 @@

demo'Demo',(3args)(args)eWG'Items'

RUN:
:If 3=⎕NC demo
''
'Running "',demo,'" with',((~EWC.USEWIN32)/'out'),' Win32'
Expand Down
12 changes: 10 additions & 2 deletions demo/Initialise.aplf
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
Initialise connected;r
Initialise connected;r;m;demo

(EWC.MODE=0)0 Only in webby modes
DemoMenu connected

:If (_EWC.QUERY)i_EWC.QUERY[;1]'Demo'
demo'Demo',_EWC.QUERY[i;2]
:AndIf 3=⎕NC demo
demo CBRunDemo ''
:Else
DemoMenu connected
:EndIf

:If EWC.MODE=2
eDQ 'F1'
:EndIf

0 comments on commit 387bcee

Please sign in to comment.