mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-15 01:52:42 +03:00
Now responds to http close requests; kills timer sessions.
This commit is contained in:
parent
fe8512efff
commit
0965f2a50f
@ -36,8 +36,10 @@
|
||||
==
|
||||
:: helper library that lets an app handle an EventSource.
|
||||
::
|
||||
:: TODO: This doesn't even attempt to deal with sequence numbers.
|
||||
::
|
||||
++ event-source
|
||||
|_ m=(map session=@ud [=bone last-id=@ud])
|
||||
|_ m=(map =bone last-id=@ud)
|
||||
++ abet m
|
||||
:: +start-session: called by app to start a session and send first event
|
||||
::
|
||||
@ -55,30 +57,22 @@
|
||||
(wall-to-output data)
|
||||
complete=%.n
|
||||
== ==
|
||||
m
|
||||
|
||||
::
|
||||
:: %_ +>.$
|
||||
:: :: +reconnect-session: reconnect an old session to a new http pipe
|
||||
:: ::
|
||||
:: :: HTTP sessions can be killed
|
||||
:: ::
|
||||
:: ++ reconnect-session
|
||||
:: |= [session=@ud =bone last-seen=@ud]
|
||||
|
||||
:: :: +confirm-
|
||||
:: ::
|
||||
:: ++ confirm-
|
||||
|
||||
(~(put by m) bone 0)
|
||||
:: +session-stopped: external notification that a session ended
|
||||
::
|
||||
++ session-stopped
|
||||
|= =bone
|
||||
^- _m
|
||||
::
|
||||
(~(del by m) bone)
|
||||
:: +send-message: sends a message based on the continuation
|
||||
::
|
||||
++ send-message
|
||||
|= [=bone data=wall]
|
||||
^- [(list move) _m]
|
||||
:- :~ :* bone %http-response
|
||||
%continue
|
||||
(wall-to-output data)
|
||||
complete=%.n
|
||||
== ==
|
||||
m
|
||||
:- [bone %http-response %continue (wall-to-output data) complete=%.n]~
|
||||
(~(jab by m) bone |=(a=@ud +(a)))
|
||||
:: +wall-to-output: changes our raw text lines to a text/event-stream
|
||||
::
|
||||
++ wall-to-output
|
||||
|= =wall
|
||||
@ -131,7 +125,7 @@
|
||||
|%
|
||||
::
|
||||
+$ state
|
||||
$: events=(map session=@ud [=bone last-id=@ud])
|
||||
$: events=(map =bone last-id=@ud)
|
||||
==
|
||||
--
|
||||
::
|
||||
@ -154,9 +148,6 @@
|
||||
~& [%bound success]
|
||||
[~ this]
|
||||
::
|
||||
:: TODO: Before we can actually add EventSource()s, we need to have %thud
|
||||
:: handling working.
|
||||
::
|
||||
++ handle-start-stream
|
||||
|= req=http-request:light
|
||||
^- (quip move _this)
|
||||
@ -175,7 +166,11 @@
|
||||
++ wake
|
||||
|= [wir=wire ~]
|
||||
^- (quip move _this)
|
||||
:: ~& [%tick wir now.bow]
|
||||
?. (~(has by events) ost.bow)
|
||||
~& [%closed wir now.bow]
|
||||
[~ this]
|
||||
::
|
||||
~& [%timer-tick wir now.bow]
|
||||
::
|
||||
=^ moves events
|
||||
(~(send-message event-source events) ost.bow ["{<now.bow>}" ~])
|
||||
@ -184,8 +179,7 @@
|
||||
:- ^- move
|
||||
[ost.bow %wait /timer (add now.bow ~s1)]
|
||||
moves
|
||||
::
|
||||
:: received when we have a
|
||||
:: +poke-handle-http-request: received on a new connection established
|
||||
::
|
||||
++ poke-handle-http-request
|
||||
|= [authenticated=? secure=? address=address:light req=http-request:light]
|
||||
@ -215,4 +209,15 @@
|
||||
[%continue [~ (part2 name)] %.y]
|
||||
==
|
||||
==
|
||||
:: +poke-handle-http-cancel: received when a connection was killed
|
||||
::
|
||||
++ poke-handle-http-cancel
|
||||
|= [authenticated=? secure=? address=address:light req=http-request:light]
|
||||
^- (quip move _this)
|
||||
:: the only long lived connections we keep state about are the stream ones.
|
||||
::
|
||||
=. events
|
||||
(~(session-stopped event-source events) ost.bow)
|
||||
::
|
||||
[~ this]
|
||||
--
|
||||
|
@ -142,9 +142,15 @@
|
||||
:: authenticated: whether the user was logged in
|
||||
::
|
||||
authenticated=?
|
||||
:: url: the original url of this request
|
||||
:: secure: whether this request was sent over an encrypted channel
|
||||
::
|
||||
url=@t
|
||||
secure=?
|
||||
:: address: address of the original sender
|
||||
::
|
||||
=address
|
||||
:: http-request: the original request
|
||||
::
|
||||
=http-request
|
||||
:: code: the status code, if sent
|
||||
::
|
||||
code=(unit @ud)
|
||||
@ -334,7 +340,9 @@
|
||||
=| record=outstanding-connection
|
||||
=. action.record u.action
|
||||
=. authenticated.record authenticated
|
||||
=. url.record url.http-request
|
||||
=. secure.record secure
|
||||
=. address.record address
|
||||
=. http-request.record http-request
|
||||
::
|
||||
=. connections.state (~(put by connections.state) duct record)
|
||||
::
|
||||
@ -366,7 +374,11 @@
|
||||
:: %handle-http-request type.
|
||||
::
|
||||
^- cush:gall
|
||||
[app.u.action %poke %handle-http-request !>([authenticated secure address http-request])]
|
||||
:* app.u.action
|
||||
%poke
|
||||
%handle-http-request
|
||||
!>([authenticated secure address http-request])
|
||||
==
|
||||
::
|
||||
%login-handler
|
||||
(handle-request:authentication secure address http-request)
|
||||
@ -375,10 +387,41 @@
|
||||
::
|
||||
++ cancel-request
|
||||
^- [(list move) server-state]
|
||||
:: TODO: Timer stuff is currently commented out at the C layer.
|
||||
::
|
||||
~& [%cancel-request duct]
|
||||
[~ state]
|
||||
::
|
||||
?~ connection=(~(get by connections.state) duct)
|
||||
:: nothing has handled this connection
|
||||
::
|
||||
[~ state]
|
||||
::
|
||||
?- -.action.u.connection
|
||||
::
|
||||
%gen
|
||||
~& [%do-something-to-stop-ford duct]
|
||||
[~ state]
|
||||
::
|
||||
%app
|
||||
:_ state
|
||||
:_ ~
|
||||
:^ duct %pass /run-app/[app.action.u.connection]
|
||||
^- note
|
||||
:^ %g %deal [our our]
|
||||
:: todo: i don't entirely understand gall; there's a way to make a gall
|
||||
:: use a %handle arm instead of a sub-%poke with the
|
||||
:: %handle-http-request type.
|
||||
::
|
||||
^- cush:gall
|
||||
:* app.action.u.connection
|
||||
%poke
|
||||
%handle-http-cancel
|
||||
=, u.connection
|
||||
!>([authenticated secure address http-request])
|
||||
==
|
||||
::
|
||||
%login-handler
|
||||
[~ state]
|
||||
==
|
||||
:: +return-static-data-on-duct: returns one piece of data all at once
|
||||
::
|
||||
++ return-static-data-on-duct
|
||||
|
Loading…
Reference in New Issue
Block a user