eyre: better userspace libraries

This commit is contained in:
Philip Monk 2019-11-09 12:22:59 -08:00
parent 47e3b260d5
commit 1d1e9c0e16
No known key found for this signature in database
GPG Key ID: B66E1F02604E44EC
3 changed files with 47 additions and 38 deletions

View File

@ -9,25 +9,8 @@
=, format
::
%+ verb &
%- http-handler
^- agent:mall
%+ http-handler
%- require-authorization:app
|= =inbound-request:eyre
^- response:http-handler
=/ request-line (parse-request-line url.request.inbound-request)
=/ back-path (flop site.request-line)
=/ name=@t
=/ back-path (flop site.request-line)
?~ back-path
''
i.back-path
::
?~ back-path
not-found:gen
?: =(name 'tile')
(js-response:gen tile-js)
not-found:gen
::
|_ =bowl:mall
+* this .
def ~(. (default-agent this %|) bowl)
@ -42,7 +25,30 @@
==
++ on-save on-save:def
++ on-load on-load:def
++ on-poke on-poke:def
++ on-poke
|= [=mark =vase]
^- (quip card:agent:mall _this)
?. ?=(%http-request mark)
(on-poke:def mark vase)
=+ !<([=path =inbound-request:eyre] vase)
:_ this
%+ give-simple-payload:app path
%+ require-authorization:app inbound-request
|= =inbound-request:eyre
=/ request-line (parse-request-line url.request.inbound-request)
=/ back-path (flop site.request-line)
=/ name=@t
=/ back-path (flop site.request-line)
?~ back-path
''
i.back-path
::
?~ back-path
not-found:gen
?: =(name 'tile')
(js-response:gen tile-js)
not-found:gen
::
++ on-watch
|= =path
^- (quip card:agent:mall _this)

View File

@ -1,11 +1,7 @@
:: wrap an http handler without having to worry about subscriptions
:: delay incoming http requests until eyre is subscribed to responses.
::
|%
+$ response simple-payload:http
+$ handler $-(inbound-request:eyre response)
--
|= [=handler =agent:mall]
=| state=[count=@ud map=(map app-id=@ud response)]
|= =agent:mall
=| state=[count=@ud map=(map app-id=@ud inbound-request:eyre)]
^- agent:mall
|_ =bowl:mall
+* this .
@ -34,10 +30,9 @@
=^ cards agent (on-poke:ag mark vase)
[cards this]
=+ !<([eyre-id=@ud =inbound-request:eyre] vase)
=/ response (handler inbound-request)
=/ app-id count.state
=: count.state +(count.state)
map.state (~(put by map.state) app-id response)
map.state (~(put by map.state) app-id inbound-request)
==
:_ this :_ ~
[%pass / %arvo %e %start-watching eyre-id app-id]
@ -49,18 +44,17 @@
=^ cards agent (on-watch:ag path)
[cards this]
=/ app-id (slav %ud i.t.path)
=/ response (~(get by map.state) app-id)
:_ this(map.state (~(del by map.state) app-id))
?~ response
=/ request (~(get by map.state) app-id)
=. map.state (~(del by map.state) app-id)
?~ request
:_ this
^- (list card:agent:mall)
:~ [%give %fact `path %http-response-cancel !>(~)]
[%give %kick `path ~]
==
^- (list card:agent:mall)
:~ [%give %fact `path %http-response-header !>(response-header.u.response)]
[%give %fact `path %http-response-data !>(data.u.response)]
[%give %kick `path ~]
==
=^ cards agent
(on-poke:ag %http-request !>([path u.request]))
[cards this]
::
++ on-leave
|= =path

View File

@ -25,8 +25,9 @@
:: +require-authorization: redirect to the login page when unauthenticated
::
++ require-authorization
|= handler=$-(inbound-request:eyre simple-payload:http)
|= =inbound-request:eyre
|= $: =inbound-request:eyre
handler=$-(inbound-request:eyre simple-payload:http)
==
^- simple-payload:http
::
?: authenticated.inbound-request
@ -39,6 +40,14 @@
"/~/login?redirect={(trip url.request.inbound-request)}"
[[307 ['location' redirect]~] ~]
::
++ give-simple-payload
|= [=path =simple-payload:http]
^- (list card:agent:mall)
:~ [%give %fact `path %http-response-header !>(response-header.simple-payload)]
[%give %fact `path %http-response-data !>(data.simple-payload)]
[%give %kick `path ~]
==
::
++ html-response
|= oct-html=octs
^- http-event:http