|
17 | 17 | :: |
18 | 18 | ++ on-init |
19 | 19 | ^- (quip card _this) |
20 | | - `this |
| 20 | + :_ this |
| 21 | + ~[[%pass /eyre/connect %arvo %e %connect [~ /'~groundseg'/roller] dap.bowl]] |
21 | 22 | :: |
22 | 23 | ++ on-save |
23 | 24 | ^- vase |
|
26 | 27 | ++ on-load |
27 | 28 | |= old-state=vase |
28 | 29 | ^- (quip card _this) |
29 | | - =/ old !<(versioned-state old-state) |
30 | | - ?- -.old |
31 | | - %0 `this(state old) |
32 | | - == |
| 30 | + =/ old=state-0 |
| 31 | + =/ loaded (mule |.(!<(state-0 old-state))) |
| 32 | + ?: ?=(%& -.loaded) p.loaded |
| 33 | + *state-0 |
| 34 | + :_ this(state old) |
| 35 | + ~[[%pass /eyre/connect %arvo %e %connect [~ /'~groundseg'/roller] dap.bowl]] |
33 | 36 | :: |
34 | 37 | ++ on-poke |
35 | 38 | |= [=mark =vase] |
36 | 39 | ^- (quip card _this) |
37 | 40 | |^ |
38 | 41 | ?> =(src.bowl our.bowl) |
39 | 42 | ?+ mark (on-poke:def mark vase) |
| 43 | + %handle-http-request |
| 44 | + (handle-http !<([@ta inbound-request:eyre] vase)) |
40 | 45 | :: toggle lick port |
41 | 46 | %port |
42 | 47 | =^ cards state |
|
53 | 58 | [cards this] |
54 | 59 | == |
55 | 60 | :: |
| 61 | + ++ handle-http |
| 62 | + |= [eid=@ta req=inbound-request:eyre] |
| 63 | + ^- (quip card _this) |
| 64 | + ?: =(%'OPTIONS' method.request.req) |
| 65 | + :_ this |
| 66 | + %^ give-http eid |
| 67 | + [204 ~[['access-control-allow-origin' '*'] ['access-control-allow-methods' 'POST, OPTIONS'] ['access-control-allow-headers' 'Content-Type, X-Groundseg-Roller-URL'] ['access-control-max-age' '3600']]] |
| 68 | + ~ |
| 69 | + [[(fetch-roller eid req)]~ this] |
| 70 | + :: |
56 | 71 | ++ handle-port |
57 | 72 | |= open=? |
58 | 73 | ^- (quip card _state) |
|
72 | 87 | |= b=@ |
73 | 88 | ^- (quip card _state) |
74 | 89 | `state(alive now.bowl) |
| 90 | + :: |
| 91 | + ++ roller-target |
| 92 | + |= headers=(list [@t @t]) |
| 93 | + ^- @t |
| 94 | + =/ target (get-header:http 'x-groundseg-roller-url' headers) |
| 95 | + ?~ target |
| 96 | + 'https://roller.urbit.org/v1/roller' |
| 97 | + u.target |
| 98 | + :: |
| 99 | + ++ fetch-roller |
| 100 | + |= [eid=@ta req=inbound-request:eyre] |
| 101 | + ^- card |
| 102 | + =/ request=request:http request.req |
| 103 | + =. url.request (roller-target header-list.request) |
| 104 | + =. header-list.request |
| 105 | + %+ skip header-list.request |
| 106 | + |= [k=@t @t] |
| 107 | + ?| =('cookie' k) |
| 108 | + =('x-groundseg-roller-url' k) |
| 109 | + == |
| 110 | + =. header-list.request |
| 111 | + =- (set-header:http 'forwarded' - header-list.request) |
| 112 | + %+ rap 3 |
| 113 | + :~ 'for="groundseg";' |
| 114 | + 'proto=' ?:(secure.req 'https' 'http') |
| 115 | + == |
| 116 | + [%pass /roller-fetch/[eid]/(scot %t url.request) %arvo %i %request request *outbound-config:iris] |
| 117 | + :: |
| 118 | + ++ give-http |
| 119 | + |= [eid=@ta =response-header:http data=(unit octs)] |
| 120 | + ^- (list card) |
| 121 | + =/ =path /http-response/[eid] |
| 122 | + :~ [%give %fact ~[path] %http-response-header !>(response-header)] |
| 123 | + [%give %fact ~[path] %http-response-data !>(data)] |
| 124 | + [%give %kick ~[path] ~] |
| 125 | + == |
75 | 126 | -- |
76 | 127 | ++ on-watch :: on-watch:def |
77 | 128 | |= =path |
78 | 129 | ^- (quip card _this) |
79 | 130 | ?+ path (on-watch:def path) |
| 131 | + [%http-response @ ~] |
| 132 | + `this |
80 | 133 | [%broadcast ~] |
81 | 134 | :_ this(alive now.bowl) |
82 | 135 | :~ |
|
92 | 145 | ++ on-arvo |
93 | 146 | |= [=wire sign=sign-arvo] |
94 | 147 | ^- (quip card _this) |
95 | | - ?. ?=([%lick %soak *] sign) (on-arvo:def +<) |
96 | | - ?+ [mark noun]:sign (on-arvo:def +<) |
97 | | - [%connect ~] |
98 | | - ((slog 'groundseg socket connected' ~) `this) |
99 | | - :: |
100 | | - [%disconnect ~] |
101 | | - ((slog 'groundseg socket disconnected' ~) `this) |
102 | | - :: |
103 | | - [%error *] |
104 | | - ((slog leaf+"socket {(trip ;;(@t noun.sign))}" ~) `this) |
105 | | - :: |
106 | | - [%broadcast *] |
107 | | - ?. ?=(@ noun.sign) |
108 | | - ((slog 'invalid broadcast' ~) `this) |
109 | | - ?: (gte `@dr`(sub now.bowl alive.state) ~s15) |
| 148 | + |^ |
| 149 | + ?+ wire |
| 150 | + ?. ?=([%lick %soak *] sign) `this |
| 151 | + ?+ [mark noun]:sign `this |
| 152 | + [%connect ~] |
| 153 | + ((slog 'groundseg socket connected' ~) `this) |
| 154 | + :: |
| 155 | + [%disconnect ~] |
| 156 | + ((slog 'groundseg socket disconnected' ~) `this) |
| 157 | + :: |
| 158 | + [%error *] |
| 159 | + ((slog leaf+"socket {(trip ;;(@t noun.sign))}" ~) `this) |
| 160 | + :: |
| 161 | + [%broadcast *] |
| 162 | + ?. ?=(@ noun.sign) |
| 163 | + ((slog 'invalid broadcast' ~) `this) |
| 164 | + ?: (gte `@dr`(sub now.bowl alive.state) ~s15) |
| 165 | + :_ this |
| 166 | + :~ [%pass /lick %arvo %l %shut /'groundseg.sock'] |
| 167 | + == |
110 | 168 | :_ this |
111 | | - :~ [%pass /lick %arvo %l %shut /'groundseg.sock'] |
| 169 | + :~ [%give %fact ~[/broadcast] %broadcast !>(`broadcast`noun.sign)] |
112 | 170 | == |
113 | | - :_ this |
114 | | - :~ [%give %fact ~[/broadcast] %broadcast !>(`broadcast`noun.sign)] |
115 | 171 | == |
| 172 | + [%eyre %connect ~] |
| 173 | + ?> ?=(%bound +<.sign) |
| 174 | + ?: accepted.sign |
| 175 | + ((slog 'groundseg roller proxy bound' ~) `this) |
| 176 | + ((slog 'groundseg roller proxy bind failed' ~) `this) |
| 177 | + [%roller-fetch @ @ ~] |
| 178 | + =/ eid=@ta i.t.wire |
| 179 | + ?> ?=([%iris %http-response *] sign) |
| 180 | + =* res client-response.sign |
| 181 | + =? res ?=(%progress -.res) |
| 182 | + [%cancel ~] |
| 183 | + ?: ?=(%cancel -.res) |
| 184 | + :_ this |
| 185 | + (give-status eid 502 'cancelled') |
| 186 | + ?> ?=(%finished -.res) |
| 187 | + :_ this |
| 188 | + %^ give-http eid |
| 189 | + [status-code.response-header.res (response-headers headers.response-header.res)] |
| 190 | + ?~ full-file.res ~ |
| 191 | + `data.u.full-file.res |
116 | 192 | == |
| 193 | + :: |
| 194 | + ++ give-http |
| 195 | + |= [eid=@ta =response-header:http data=(unit octs)] |
| 196 | + ^- (list card) |
| 197 | + =/ =path /http-response/[eid] |
| 198 | + :~ [%give %fact ~[path] %http-response-header !>(response-header)] |
| 199 | + [%give %fact ~[path] %http-response-data !>(data)] |
| 200 | + [%give %kick ~[path] ~] |
| 201 | + == |
| 202 | + :: |
| 203 | + ++ give-status |
| 204 | + |= [eid=@ta status=@ud msg=@t] |
| 205 | + ^- (list card) |
| 206 | + %^ give-http eid |
| 207 | + [status ~[['content-type' 'text/plain']]] |
| 208 | + `(as-octs:mimes:html msg) |
| 209 | + :: |
| 210 | + ++ response-headers |
| 211 | + |= headers=(list [@t @t]) |
| 212 | + ^- (list [@t @t]) |
| 213 | + =/ clean=(list [@t @t]) |
| 214 | + %+ skip headers |
| 215 | + |= [key=@t value=@t] |
| 216 | + ?| =(key 'transfer-encoding') |
| 217 | + =(key 'connection') |
| 218 | + == |
| 219 | + %+ weld clean |
| 220 | + ~[['x-groundseg-roller' 'finished'] ['access-control-allow-origin' '*']] |
| 221 | + -- |
117 | 222 | :: |
118 | 223 | ++ on-fail on-fail:def |
119 | 224 | -- |
0 commit comments