moves +http-server interface core into +eyre

This commit is contained in:
Joe Bryan 2019-07-03 23:09:44 -07:00
parent 62522f87c1
commit e0f17b0ff1
21 changed files with 222 additions and 244 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:0fbfb721407b2160dae95f458693ec6df89d2643e58a9c736acaed65e4ba70f5
size 8327488
oid sha256:6571b65d5615573b794a2d00799b45f5dc713b2f7f6f5eee59f35214deda8af8
size 8399855

View File

@ -147,7 +147,7 @@
:: +card: output effect payload
::
+$ card
$% [%connect wire =binding:http-server app=term]
$% [%connect wire =binding:eyre app=term]
[%http-response =http-event:http]
[%poke wire dock poke]
[%request wire request:http outbound-config:http-client]
@ -1193,7 +1193,7 @@
:: Used to serve the domain validation challenge
::
++ poke-handle-http-request
|= =inbound-request:http-server
|= =inbound-request:eyre
^- (quip move _this)
~& [%handle-http +<]
=/ url=(unit (pair pork:eyre quay:eyre))
@ -1315,7 +1315,7 @@
:: +bound: response to %connect binding request
::
++ bound
|= [=wire accepted=? =binding:http-server]
|= [=wire accepted=? =binding:eyre]
?: accepted
[~ this]
:: XX better error message

View File

@ -477,7 +477,7 @@
:: +bound: lient tells us we successfully bound our server to the ~chat url
::
++ bound
|= [wir=wire success=? binding=binding:http-server]
|= [wir=wire success=? binding=binding:eyre]
^- (quip move _this)
[~ this]
::
@ -485,7 +485,7 @@
::
++ poke-handle-http-request
%- (require-authorization:app ost.bol move this)
|= =inbound-request:http-server
|= =inbound-request:eyre
^- (quip move _this)
::
=+ request-line=(parse-request-line url.request.inbound-request)

View File

@ -21,7 +21,7 @@
+$ card
$% [%poke wire dock poke]
[%http-response =http-event:http]
[%connect wire binding:http-server term]
[%connect wire binding:eyre term]
[%diff %json json]
==
::
@ -32,7 +32,7 @@
++ this .
::
++ bound
|= [wir=wire success=? binding=binding:http-server]
|= [wir=wire success=? binding=binding:eyre]
^- (quip move _this)
[~ this]
::
@ -60,7 +60,7 @@
::
++ poke-handle-http-request
%- (require-authorization:app ost.bol move this)
|= =inbound-request:http-server
|= =inbound-request:eyre
^- (quip move _this)
=/ request-line (parse-request-line url.request.inbound-request)
=/ back-path (flop site.request-line)

View File

@ -15,7 +15,7 @@
+$ in-poke-data
$% [%dns-authority =authority]
[%dns-bind =ship =target]
[%handle-http-request =inbound-request:http-server]
[%handle-http-request =inbound-request:eyre]
==
+$ out-poke-data
$% [%dns-bind =ship =target]

View File

@ -27,7 +27,7 @@
::
+$ card
$% [%http-response =http-event:http]
[%connect wire binding:http-server term]
[%connect wire binding:eyre term]
[%peer wire dock path]
[%diff %json json]
==
@ -53,7 +53,7 @@
[~ this(sta u.old)]
::
++ bound
|= [wir=wire success=? binding=binding:http-server]
|= [wir=wire success=? binding=binding:eyre]
^- (quip move _this)
[~ this]
::
@ -110,7 +110,7 @@
::
++ poke-handle-http-request
%- (require-authorization:app ost.bol move this)
|= =inbound-request:http-server
|= =inbound-request:eyre
^- (quip move _this)
::
=+ request-line=(parse-request-line url.request.inbound-request)

View File

@ -10,7 +10,7 @@
:: +card: output effect payload
::
+$ card
$% [%connect wire binding:http-server term]
$% [%connect wire binding:eyre term]
[%http-response =http-event:http]
[%peel wire dock mark path]
[%poke wire dock poke]
@ -41,13 +41,13 @@
:: alerts us that we were bound. we need this because the vane calls back.
::
++ bound
|= [wir=wire success=? binding=binding:http-server]
|= [wir=wire success=? binding=binding:eyre]
^- (quip move _this)
[~ this]
::
++ poke-handle-http-request
%- (require-authorization:app ost.bow move this)
|= =inbound-request:http-server
|= =inbound-request:eyre
^- (quip move _this)
?^ job.state
:_ this
@ -101,7 +101,7 @@
:: +poke-handle-http-cancel: received when a connection was killed
::
++ poke-handle-http-cancel
|= =inbound-request:http-server
|= =inbound-request:eyre
^- (quip move _this)
:: the only long lived connections we keep state about are the stream ones.
::

View File

@ -6,8 +6,8 @@
:: +card: output effect payload
::
+$ card
$% [%connect wire binding:http-server term]
[%disconnect wire binding:http-server]
$% [%connect wire binding:eyre term]
[%disconnect wire binding:eyre]
[%http-response =http-event:http]
==
::
@ -28,7 +28,7 @@
:: alerts us that we were bound. we need this because the vane calls back.
::
++ bound
|= [wir=wire success=? binding=binding:http-server]
|= [wir=wire success=? binding=binding:eyre]
^- (quip move _this)
[~ this]
::
@ -44,7 +44,7 @@
::
++ poke-handle-http-request
%- (require-authorization:app ost.bow move this)
|= =inbound-request:http-server
|= =inbound-request:eyre
^- (quip move _this)
[[ost.bow %http-response (js-response:app session-js)]~ this]
::

View File

@ -92,8 +92,8 @@
::
++ require-authorization
|* [=bone move=mold this=*]
|= handler=$-(inbound-request:http-server (quip move _this))
|= =inbound-request:http-server
|= handler=$-(inbound-request:eyre (quip move _this))
|= =inbound-request:eyre
^- (quip move _this)
::
?: authenticated.inbound-request
@ -128,7 +128,7 @@
:: alerts us that we were bound. we need this because the vane calls back.
::
++ bound
|= [wir=wire success=? binding=binding:http-server]
|= [wir=wire success=? binding=binding:eyre]
~& [%bound success]
[~ this]
::
@ -160,7 +160,7 @@
::
++ poke-handle-http-request
%- (require-authorization ost.bow move this)
|= =inbound-request:http-server
|= =inbound-request:eyre
^- (quip move _this)
::
=+ request-line=(parse-request-line url.request.inbound-request)
@ -190,7 +190,7 @@
:: +poke-handle-http-cancel: received when a connection was killed
::
++ poke-handle-http-cancel
|= =inbound-request:http-server
|= =inbound-request:eyre
^- (quip move _this)
:: the only long lived connections we keep state about are the stream ones.
::

View File

@ -24,7 +24,7 @@
+$ card
$% [%poke wire dock poke]
[%http-response =http-event:http]
[%connect wire binding:http-server term]
[%connect wire binding:eyre term]
[%diff %json json]
[%wait wire @da]
[%rest wire @da]
@ -37,7 +37,7 @@
++ this .
::
++ bound
|= [wir=wire success=? binding=binding:http-server]
|= [wir=wire success=? binding=binding:eyre]
^- (quip move _this)
[~ this]
::
@ -87,7 +87,7 @@
::
++ poke-handle-http-request
%- (require-authorization:app ost.bol move this)
|= =inbound-request:http-server
|= =inbound-request:eyre
^- (quip move _this)
=/ request-line (parse-request-line url.request.inbound-request)
=/ back-path (flop site.request-line)

View File

@ -21,7 +21,7 @@
$% [%poke wire dock poke]
[%http-response =http-event:http]
[%diff %json json]
[%connect wire binding:http-server term]
[%connect wire binding:eyre term]
[%request wire request:http outbound-config:http-client]
[%wait wire @da]
==
@ -38,7 +38,7 @@
++ this .
::
++ bound
|= [wir=wire success=? binding=binding:http-server]
|= [wir=wire success=? binding=binding:eyre]
^- (quip move _this)
[~ this]
::
@ -126,7 +126,7 @@
::
++ poke-handle-http-request
%- (require-authorization:app ost.bol move this)
|= =inbound-request:http-server
|= =inbound-request:eyre
^- (quip move _this)
=+ request-line=(parse-request-line url.request.inbound-request)
=+ back-path=(flop site.request-line)

View File

@ -47,9 +47,9 @@
[%diff diff]
[%build wire ? schematic:ford]
[%kill wire ~]
[%connect wire binding:http-server term]
[%connect wire binding:eyre term]
[%http-response http-event:http]
[%disconnect binding:http-server]
[%disconnect binding:eyre]
==
::
+$ poke
@ -1237,7 +1237,7 @@
==
::
++ bound
|= [wir=wire success=? binding=binding:http-server]
|= [wir=wire success=? binding=binding:eyre]
^- (quip move _this)
[~ this]
::
@ -1245,7 +1245,7 @@
::
++ poke-handle-http-request
%- (require-authorization:app ost.bol move this)
|= =inbound-request:http-server
|= =inbound-request:eyre
^- (quip move _this)
::
=/ request-line (parse-request-line url.request.inbound-request)
@ -1431,7 +1431,7 @@
:: +poke-handle-http-cancel: received when a connection was killed
::
++ poke-handle-http-cancel
|= =inbound-request:http-server
|= =inbound-request:eyre
^- (quip move _this)
[~ this]
::

View File

@ -6,7 +6,7 @@
::
+$ card
$% [%http-response =http-event:http]
[%connect wire binding:http-server term]
[%connect wire binding:eyre term]
[%peer wire dock path]
[%quit ~]
[%poke wire dock poke]

View File

@ -42,7 +42,7 @@
{$flog wire flog:dill} ::
[%mint wire p=ship q=safe:rights:jael]
{$nuke wire ship} ::
[%serve wire binding:http-server generator:http-server]
[%serve wire binding:eyre generator:eyre]
{$poke wire dock pear} ::
{$rest wire @da} ::
{$wait wire @da} ::
@ -218,11 +218,11 @@
(emit %flog ~ %text "woot: {<[way cop]>}")
::
++ poke-serve
|= [=binding:http-server =generator:http-server] =< abet
|= [=binding:eyre =generator:eyre] =< abet
(emit %serve /helm/serv binding generator)
::
++ take-bound
|= [wir=wire success=? binding=binding:http-server] =< abet
|= [wir=wire success=? binding=binding:eyre] =< abet
(emit %flog ~ %text "bound: {<success>}")
::
++ poke-tlon-init-stream

View File

@ -1,4 +1,4 @@
=, http-server
=, eyre
|%
::
:: +parse-request-line: take a cord and parse out a url
@ -25,8 +25,8 @@
::
++ require-authorization
|* [=bone move=mold this=*]
|= handler=$-(inbound-request:http-server (quip move _this))
|= =inbound-request:http-server
|= handler=$-(inbound-request:eyre (quip move _this))
|= =inbound-request:eyre
^- (quip move _this)
::
?: authenticated.inbound-request
@ -79,7 +79,7 @@
[%start [404 ~] ~ %.y]
::
++ login-redirect
|= =inbound-request:http-server
|= =inbound-request:eyre
^- http-event:http
=/ redirect=cord
%- crip

View File

@ -198,7 +198,7 @@
:: Incoming HTTP requests
::
++ bind-route-raw
|= [=binding:http-server =term]
|= [=binding:eyre =term]
=/ m (async ,~)
^- form:m
(send-raw-card [%connect / binding term])
@ -216,7 +216,7 @@
[%done success.sign]
::
++ bind-route
|= [=binding:http-server =term]
|= [=binding:eyre =term]
=/ m (async ?)
^- form:m
;< ~ bind:m (bind-route-raw binding term)

View File

@ -406,7 +406,7 @@
:: Receive route binding notification
::
++ bound
|= [=wire success=? =binding:http-server]
|= [=wire success=? =binding:eyre]
^- (quip move _this-tapp)
(take-async bowl `[wire %bound success binding])
::

View File

@ -12,7 +12,7 @@
[%diff out-peer-data]
[%request wire request:http outbound-config:http-client]
[%cancel-request wire ~]
[%connect wire binding:http-server term]
[%connect wire binding:eyre term]
[%http-response =http-event:http]
[%rule wire %turf %put turf]
==
@ -24,7 +24,7 @@
[%coup =dock error=(unit tang)]
[%quit =dock =path]
[%reap =dock =path error=(unit tang)]
[%bound success=? =binding:http-server]
[%bound success=? =binding:eyre]
[%http-response response=client-response:http-client]
==
::

View File

@ -64,7 +64,7 @@
task:able:dill ::
== ::
$: %e ::
$>(%wegh task:able:http-server) ::
$>(%wegh task:able:eyre) ::
== ::
$: %f ::
$>(%wegh task:able:ford) ::
@ -112,7 +112,7 @@
$>(%blit gift:able:dill) ::
== ::
$: %e ::
$>(%mass gift:able:http-server) ::
$>(%mass gift:able:eyre) ::
== ::
$: %f ::
$>(%mass gift:able:ford) ::

View File

@ -2,7 +2,7 @@
:: lighter than eyre
::
|= pit=vase
=, http-server
=, eyre
:: internal data structures
::
=> =~
@ -1460,7 +1460,7 @@
^- (list move)
:_ moves
:+ p.state.u.channel %give
^- gift:able:http-server
^- gift:able
:* %response %continue
::
^= data

View File

@ -864,16 +864,169 @@
== ::
-- ::dill
:: ::::
:::: ++eyre :: (1e) oldweb
:::: ++eyre :: (1e) http-server
:: ::::
++ eyre ^?
|%
++ bale :: driver state
|* a/_* :: %jael keys type
$: {our/ship now/@da eny/@uvJ byk/beak} :: base info
{usr/user dom/(list @t)} :: req user, domain
key/a :: secrets from %jael
== ::
++ able
|%
++ gift
$% :: set-config: configures the external http server
::
:: TODO: We need to actually return a (map (unit @t) http-config)
:: so we can apply configurations on a per-site basis
::
[%set-config =http-config]
:: response: response to an event from earth
::
[%response =http-event:http]
:: response to a %connect or %serve
::
:: :accepted is whether :binding was valid. Duplicate bindings are
:: not allowed.
::
[%bound accepted=? =binding]
:: memory usage report
::
[%mass p=mass]
==
::
++ task
$~ [%vega ~]
$% :: event failure notification
::
$>(%crud vane-task)
:: initializes ourselves with an identity
::
$>(%init vane-task)
:: new unix process
::
:: XX use +vane-task
::
[%born p=(list host)]
:: report upgrade
::
$>(%vega vane-task)
:: notifies us of the ports of our live http servers
::
[%live insecure=@ud secure=(unit @ud)]
:: update http configuration
::
[%rule =http-rule]
:: starts handling an inbound http request
::
[%request secure=? =address =request:http]
:: starts handling an backdoor http request
::
[%request-local secure=? =address =request:http]
:: cancels a previous request
::
[%cancel-request ~]
:: connects a binding to an app
::
[%connect =binding app=term]
:: connects a binding to a generator
::
[%serve =binding =generator]
:: disconnects a binding
::
:: This must be called with the same duct that made the binding in
:: the first place.
::
[%disconnect =binding]
:: memory usage request
::
$>(%wegh vane-task)
==
::
--
:: +binding: A rule to match a path.
::
:: A +binding is a system unique mapping for a path to match. A +binding
:: must be system unique because we don't want two handlers for a path;
:: what happens if there are two different actions for [~ /]?
::
+$ binding
$: :: site: the site to match.
::
:: A ~ will match the Urbit's identity site (your.urbit.org). Any
:: other value will match a domain literal.
::
site=(unit @t)
:: path: matches this prefix path
::
:: /~myapp will match /~myapp or /~myapp/longer/path
::
path=(list @t)
==
:: +generator: a generator on the local ship that handles requests
::
:: This refers to a generator on the local ship, run with a set of
:: arguments. Since http requests are time sensitive, we require that the
:: generator be on the current ship.
::
+$ generator
$: :: desk: desk on current ship that contains the generator
::
=desk
:: path: path on :desk to the generator's hoon file
::
path=(list @t)
:: args: arguments passed to the gate
::
args=*
==
:: +http-config: full http-server configuration
::
+$ http-config
$: :: secure: PEM-encoded RSA private key and cert or cert chain
::
secure=(unit [key=wain cert=wain])
:: proxy: reverse TCP proxy HTTP(s)
::
proxy=_|
:: log: keep HTTP(s) access logs
::
log=?
:: redirect: send 301 redirects to upgrade HTTP to HTTPS
::
:: Note: requires certificate.
::
redirect=?
==
:: +http-rule: update configuration
::
+$ http-rule
$% :: %cert: set or clear certificate and keypair
::
[%cert cert=(unit [key=wain cert=wain])]
:: %turf: add or remove established dns binding
::
[%turf action=?(%put %del) =turf]
==
:: +address: client IP address
::
+$ address
$% [%ipv4 @if]
[%ipv6 @is]
:: [%ames @p]
==
:: +inbound-request: +http-request and metadata
::
+$ inbound-request
$: :: authenticated: has a valid session cookie
::
authenticated=?
:: secure: whether this request was encrypted (https)
::
secure=?
:: address: the source address of this request
::
=address
:: request: the http-request itself
::
=request:http
==
::
++ cred :: credential
$: hut/hart :: client host
@ -995,12 +1148,6 @@
(gte i.b 224)
==
++ rout {p/(list host) q/path r/oryx s/path} :: http route (new)
++ sec-move :: driver effect
$% {$send p/hiss} :: http out
{$show p/purl} :: direct user to url
{$give p/httr} :: respond immediately
{$redo ~} :: restart request qeu
== ::
++ user knot :: username
-- ::eyre
:: ::::
@ -2273,175 +2420,6 @@
::
[status-code.header headers.header data]
--
::
::::
::
++ http-server ^?
|%
++ able
|%
++ gift
$% :: set-config: configures the external http server
::
:: TODO: We need to actually return a (map (unit @t) http-config)
:: so we can apply configurations on a per-site basis
::
[%set-config =http-config]
:: response: response to an event from earth
::
[%response =http-event:http]
:: response to a %connect or %serve
::
:: :accepted is whether :binding was valid. Duplicate bindings are
:: not allowed.
::
[%bound accepted=? =binding]
:: memory usage report
::
[%mass p=mass]
==
::
++ task
$~ [%vega ~]
$% :: event failure notification
::
$>(%crud vane-task)
:: initializes ourselves with an identity
::
$>(%init vane-task)
:: new unix process
::
:: XX use +vane-task
::
[%born p=(list host)]
:: report upgrade
::
$>(%vega vane-task)
:: notifies us of the ports of our live http servers
::
[%live insecure=@ud secure=(unit @ud)]
:: update http configuration
::
[%rule =http-rule]
:: starts handling an inbound http request
::
[%request secure=? =address =request:http]
:: starts handling an backdoor http request
::
[%request-local secure=? =address =request:http]
:: cancels a previous request
::
[%cancel-request ~]
:: connects a binding to an app
::
[%connect =binding app=term]
:: connects a binding to a generator
::
[%serve =binding =generator]
:: disconnects a binding
::
:: This must be called with the same duct that made the binding in
:: the first place.
::
[%disconnect =binding]
:: memory usage request
::
$>(%wegh vane-task)
==
::
--
:: +binding: A rule to match a path.
::
:: A +binding is a system unique mapping for a path to match. A +binding
:: must be system unique because we don't want two handlers for a path;
:: what happens if there are two different actions for [~ /]?
::
+$ binding
$: :: site: the site to match.
::
:: A ~ will match the Urbit's identity site (your.urbit.org). Any
:: other value will match a domain literal.
::
site=(unit @t)
:: path: matches this prefix path
::
:: /~myapp will match /~myapp or /~myapp/longer/path
::
path=(list @t)
==
:: +generator: a generator on the local ship that handles requests
::
:: This refers to a generator on the local ship, run with a set of
:: arguments. Since http requests are time sensitive, we require that the
:: generator be on the current ship.
::
+$ generator
$: :: desk: desk on current ship that contains the generator
::
=desk
:: path: path on :desk to the generator's hoon file
::
path=(list @t)
:: args: arguments passed to the gate
::
args=*
==
:: +host: http host
::
+$ host
(each (list @t) @if)
:: +http-config: full http-server configuration
::
+$ http-config
$: :: secure: PEM-encoded RSA private key and cert or cert chain
::
secure=(unit [key=wain cert=wain])
:: proxy: reverse TCP proxy HTTP(s)
::
proxy=_|
:: log: keep HTTP(s) access logs
::
log=?
:: redirect: send 301 redirects to upgrade HTTP to HTTPS
::
:: Note: requires certificate.
::
redirect=?
==
:: +http-rule: update configuration
::
+$ http-rule
$% :: %cert: set or clear certificate and keypair
::
[%cert cert=(unit [key=wain cert=wain])]
:: %turf: add or remove established dns binding
::
[%turf action=?(%put %del) =turf]
==
:: +address: client IP address
::
+$ address
$% [%ipv4 @if]
[%ipv6 @is]
:: [%ames @p]
==
:: +inbound-request: +http-request and metadata
::
+$ inbound-request
$: :: authenticated: has a valid session cookie
::
authenticated=?
:: secure: whether this request was encrypted (https)
::
secure=?
:: address: the source address of this request
::
=address
:: request: the http-request itself
::
=request:http
==
--
:: ::::
:::: ++xmas :: (1i) new network
:: ::::
@ -7600,7 +7578,7 @@
gift:able:behn
gift:able:clay
gift:able:dill
gift:able:http-server
gift:able:eyre
gift:able:ford
gift:able:gall
gift:able:http-client
@ -7614,7 +7592,7 @@
task:able:http-client
task:able:ford
task:able:gall
task:able:http-server
task:able:eyre
task:able:jael
==
++ note-arvo :: out request $->
@ -7623,7 +7601,7 @@
{$b task:able:behn}
{$c task:able:clay}
{$d task:able:dill}
[%e task:able:http-server]
[%e task:able:eyre]
{$f task:able:ford}
{$g task:able:gall}
[%i task:able:http-client]
@ -7640,7 +7618,7 @@
{$c gift:able:clay}
{$d gift:able:dill}
{$f gift:able:ford}
[%e gift:able:http-server]
[%e gift:able:eyre]
{$g gift:able:gall}
[%i gift:able:http-client]
{$j gift:able:jael}
@ -7685,16 +7663,16 @@
$>(%into task:able:clay)
:: %eyre: learn ports of live http servers
::
$>(%live task:able:http-server)
$>(%live task:able:eyre)
:: %iris: hear (partial) http response
::
$>(%receive task:able:http-client)
:: %eyre: starts handling an inbound http request
::
$>(%request task:able:http-server)
$>(%request task:able:eyre)
:: %eyre: starts handling an backdoor http request
::
$>(%request-local task:able:http-server)
$>(%request-local task:able:eyre)
:: %behn: wakeup
::
$>(%wake task:able:behn)