mirror of
https://github.com/urbit/shrub.git
synced 2024-11-29 14:57:12 +03:00
Got the first http fetch unit tests working.
This commit is contained in:
parent
f546626309
commit
37f978dba3
@ -97,6 +97,9 @@
|
||||
:: connection-by-id: open connections to the
|
||||
::
|
||||
connection-by-id=(map @ud [=duct =in-progress-http-request])
|
||||
:: outbound-duct: the duct to send outbound requests on
|
||||
::
|
||||
outbound-duct=duct
|
||||
==
|
||||
:: +in-progress-http-request: state around an outbound http
|
||||
::
|
||||
@ -109,6 +112,9 @@
|
||||
remaining-retries=@ud
|
||||
:: chunks: a list of partial results returned from unix
|
||||
::
|
||||
:: This list of octs must be flopped before it is composed as the
|
||||
:: final response, as we want to be able to quickly insert.
|
||||
::
|
||||
chunks=(list octs)
|
||||
:: bytes-read: the sum of the size of the :chunks
|
||||
::
|
||||
@ -694,7 +700,7 @@
|
||||
:: email discussions make it sound like fixing that might be hard, so
|
||||
:: maybe i should just live with the way it is now?
|
||||
::
|
||||
:- [duct %give %http-request id `http-request]~
|
||||
:- [outbound-duct.state %give %http-request id `http-request]~
|
||||
state
|
||||
:: +receive: receives a response to an http-request we made
|
||||
::
|
||||
@ -726,15 +732,51 @@
|
||||
?~ mime-type=(get-header 'content-type' headers.raw-http-response)
|
||||
'application/octet-stream'
|
||||
u.mime-type
|
||||
:: :- :* duct.u.connection
|
||||
:: %give
|
||||
:: %http-finished
|
||||
:: [status-code headers]:raw-http-response
|
||||
:: `[mime data:raw-http-response]
|
||||
:: ==
|
||||
:- ~
|
||||
:- :~ ^- move
|
||||
:* duct.u.connection
|
||||
%give
|
||||
%http-finished
|
||||
^- http-response-header
|
||||
[status-code headers]:raw-http-response
|
||||
::
|
||||
?~ data.raw-http-response
|
||||
~
|
||||
[~ `mime-data`[mime u.data.raw-http-response]]
|
||||
== ==
|
||||
state(connection-by-id (~(del by connection-by-id.state) id))
|
||||
[~ state]
|
||||
:: this is the initial packet of an incomplete request.
|
||||
::
|
||||
=. connection-by-id.state
|
||||
%+ ~(jab by connection-by-id.state) id
|
||||
|= [duct=^duct =in-progress-http-request:client]
|
||||
:: record the data chunk, if it exists
|
||||
::
|
||||
=? chunks.in-progress-http-request
|
||||
?=(^ data.raw-http-response)
|
||||
[u.data.raw-http-response chunks.in-progress-http-request]
|
||||
=? bytes-read.in-progress-http-request
|
||||
?=(^ data.raw-http-response)
|
||||
(add bytes-read.in-progress-http-request p.u.data.raw-http-response)
|
||||
::
|
||||
=. expected-size.in-progress-http-request
|
||||
?~ str=(get-header 'content-length' headers.raw-http-response)
|
||||
~
|
||||
::
|
||||
(rush u.str dum:ag)
|
||||
::
|
||||
[duct in-progress-http-request]
|
||||
::
|
||||
=/ connection (~(got by connection-by-id.state) id)
|
||||
:_ state
|
||||
:_ ~
|
||||
:* duct.connection
|
||||
%give
|
||||
%http-progress
|
||||
[status-code headers]:raw-http-response
|
||||
bytes-read.in-progress-http-request.connection
|
||||
expected-size.in-progress-http-request.connection
|
||||
data.raw-http-response
|
||||
==
|
||||
::
|
||||
%continue
|
||||
[~ state]
|
||||
@ -1723,7 +1765,9 @@
|
||||
~& [%todo-handle-born p.task]
|
||||
:: TODO: reset the next-id for client state here.
|
||||
::
|
||||
|
||||
:: send requests on the duct passed in with born.
|
||||
::
|
||||
=. outbound-duct.client-state.ax duct
|
||||
:: close previously open connections
|
||||
::
|
||||
:: When we have a new unix process, every outstanding open connection is
|
||||
@ -1785,7 +1829,6 @@
|
||||
:: %fetch
|
||||
::
|
||||
%fetch
|
||||
~& %todo-fetch
|
||||
=/ event-args [[our eny duct now scry-gate] client-state.ax]
|
||||
=/ fetch fetch:(per-client-event event-args)
|
||||
=^ moves client-state.ax (fetch +.task)
|
||||
@ -1800,8 +1843,10 @@
|
||||
:: %receive: receives http data from unix
|
||||
::
|
||||
%receive
|
||||
~& %todo-receive
|
||||
[~ light-gate]
|
||||
=/ event-args [[our eny duct now scry-gate] client-state.ax]
|
||||
=/ receive receive:(per-client-event event-args)
|
||||
=^ moves client-state.ax (receive +.task)
|
||||
[moves light-gate]
|
||||
::
|
||||
:: %connect / %serve
|
||||
::
|
||||
|
@ -71,6 +71,12 @@
|
||||
++ coop (unit ares) :: possible error
|
||||
++ life @ud :: ship version
|
||||
++ mime {p/mite q/octs} :: mimetyped data
|
||||
::
|
||||
::
|
||||
:: TODO: Rename to +mime once the current +mime and +mite are gone. The
|
||||
::
|
||||
+$ mime-data
|
||||
[type=@t data=octs]
|
||||
++ octs {p/@ud q/@t} :: octet-stream
|
||||
++ sock {p/ship q/ship} :: outgoing [our his]
|
||||
::+|
|
||||
@ -2022,19 +2028,19 @@
|
||||
:: final redirect.
|
||||
::
|
||||
=http-response-header
|
||||
:: bytes-fetched: bytes fetched so far
|
||||
:: bytes-read: bytes fetched so far
|
||||
::
|
||||
bytes-fetched=@ud
|
||||
:: bytes-total: the total size if response had a content-length
|
||||
bytes-read=@ud
|
||||
:: expected-size: the total size if response had a content-length
|
||||
::
|
||||
bytes-total=(unit @ud)
|
||||
expected-size=(unit @ud)
|
||||
:: incremental: data received since the last %http-progress
|
||||
::
|
||||
incremental=octs
|
||||
incremental=(unit octs)
|
||||
==
|
||||
:: final response of a download, parsed as mime if successful
|
||||
:: final response of a download, parsed as mime-data if successful
|
||||
::
|
||||
[%http-finished =http-response-header full-file=(unit mime)]
|
||||
[%http-finished =http-response-header full-file=(unit mime-data)]
|
||||
==
|
||||
::
|
||||
++ task
|
||||
@ -2063,7 +2069,7 @@
|
||||
[%cancel-fetch ~]
|
||||
:: receives http data from outside
|
||||
::
|
||||
[%receive =http-request complete=?]
|
||||
[%receive id=@ud =raw-http-response]
|
||||
:: connects a binding to an app
|
||||
::
|
||||
[%connect =binding app=term]
|
||||
@ -2201,7 +2207,7 @@
|
||||
:: the entire body before we send a %progress to the caller.
|
||||
::
|
||||
+$ http-response-header
|
||||
$% :: status: http status code
|
||||
$: :: status: http status code
|
||||
::
|
||||
status-code=@ud
|
||||
:: headers: http headers
|
||||
|
@ -1267,6 +1267,110 @@
|
||||
results8
|
||||
results9
|
||||
==
|
||||
:: +test-basic-fetch: tests a single request, single reply style http request
|
||||
::
|
||||
++ test-basic-fetch
|
||||
:: send a %born event to use /initial-born-duct for requests
|
||||
::
|
||||
=^ results1 light-gate
|
||||
%- light-call :*
|
||||
light-gate
|
||||
now=~1111.1.1
|
||||
scry=*sley
|
||||
^= call-args
|
||||
:* duct=~[/initial-born-duct] ~
|
||||
%born
|
||||
[[%.n .192.168.1.1] ~]
|
||||
==
|
||||
^= expected-moves
|
||||
:~ :* duct=~[/initial-born-duct]
|
||||
%give
|
||||
%form
|
||||
*http-config:light
|
||||
== == ==
|
||||
::
|
||||
=/ request=http-request:light
|
||||
:* %'GET'
|
||||
'http://www.example.com'
|
||||
~
|
||||
~
|
||||
==
|
||||
:: opens the http channel
|
||||
::
|
||||
=^ results2 light-gate
|
||||
%- light-call :*
|
||||
light-gate
|
||||
now=(add ~1111.1.1 ~s1)
|
||||
scry=*sley
|
||||
^= call-args
|
||||
:* duct=~[/http-get-request] ~
|
||||
%fetch
|
||||
request
|
||||
*outbound-config:light
|
||||
==
|
||||
^= expected-moves
|
||||
^- (list move:light-gate)
|
||||
:~ :* duct=~[/initial-born-duct]
|
||||
%give
|
||||
%http-request
|
||||
id=0
|
||||
~
|
||||
method=%'GET'
|
||||
url='http://www.example.com'
|
||||
~
|
||||
~
|
||||
== == ==
|
||||
:: returns the entire payload in one response
|
||||
::
|
||||
=^ results3 light-gate
|
||||
%- light-call :*
|
||||
light-gate
|
||||
now=(add ~1111.1.1 ~s1)
|
||||
scry=*sley
|
||||
^= call-args
|
||||
:+ duct=~[/initial-born-duct] ~
|
||||
^- task:able:light
|
||||
:* %receive
|
||||
id=0
|
||||
^- raw-http-response:light
|
||||
:* %start
|
||||
200
|
||||
:~ ['content-type' 'text/html']
|
||||
['content-length' '34']
|
||||
==
|
||||
::
|
||||
:- ~
|
||||
%- as-octs:mimes:html
|
||||
'''
|
||||
<html><body>Response</body></html>
|
||||
'''
|
||||
::
|
||||
complete=%.y
|
||||
== ==
|
||||
^= expected-moves
|
||||
^- (list move:light-gate)
|
||||
:~ :* duct=~[/http-get-request]
|
||||
%give
|
||||
%http-finished
|
||||
::
|
||||
:- 200
|
||||
:~ ['content-type' 'text/html']
|
||||
['content-length' '34']
|
||||
==
|
||||
::
|
||||
:- ~
|
||||
:- 'text/html'
|
||||
%- as-octs:mimes:html
|
||||
'''
|
||||
<html><body>Response</body></html>
|
||||
'''
|
||||
== == ==
|
||||
::
|
||||
;: weld
|
||||
results1
|
||||
results2
|
||||
results3
|
||||
==
|
||||
::
|
||||
++ light-call
|
||||
|= $: light-gate=_light-gate
|
||||
|
Loading…
Reference in New Issue
Block a user