eyre: respect protocol from Forwarded header
If the Forwarded header specifies the original connection is secure,
update the flag to reflect that, regardless of whether the connection
directly to the urbit was made securely.
=* headers header-list.request
:: for requests from localhost, respect the "forwarded" header
::
- =? address =([%ipv4 .127.0.0.1] address)
- (fall (forwarded-for headers) address)
+ =/ [secure=? =^address]
+ =* same [secure address]
+ ?. =([%ipv4 .127.0.0.1] address) same
+ ?~ forwards=(forwarded-params headers) same
+ :- (fall (forwarded-secure u.forwards) secure)
+ (fall (forwarded-for u.forwards) address)
::
=/ host (get-header:http 'host' headers)
=/ [=action suburl=@t]
(cat 3 '.' u.ext.request-line)
--
::
-++ forwarded-for
+++ forwarded-params
|= =header-list:http
- ^- (unit address)
- =/ forwarded=(unit @t)
+ ^- (unit (list (map @t @t)))
+ %+ biff
(get-header:http 'forwarded' header-list)
- ?~ forwarded ~
- |^ =/ forwards=(unit (list (map @t @t)))
- (unpack-header:http u.forwarded)
- ?. ?=([~ ^] forwards) ~
- =* forward i.u.forwards
+ unpack-header:http
+::
+++ forwarded-for
+ |= forwards=(list (map @t @t))
+ ^- (unit address)
+ ?. ?=(^ forwards) ~
+ =* forward i.forwards
?~ for=(~(get by forward) 'for') ~
::NOTE per rfc7239, non-ip values are also valid. they're not useful
:: for the general case, so we ignore them here. if needed,
:: request handlers are free to inspect the headers themselves.
::
- (rush u.for ip-address)
- ::
- ++ ip-address
+ %+ rush u.for
;~ sfix
;~(pose (stag %ipv4 ip4) (stag %ipv6 (ifix [lac rac] ip6)))
;~(pose ;~(pfix col dim:ag) (easy ~))
==
- --
+::
+++ forwarded-secure
+ |= forwards=(list (map @t @t))
+ ^- (unit ?)
+ ?. ?=(^ forwards) ~
+ =* forward i.forwards
+ ?~ proto=(~(get by forward) 'proto') ~
+ ?+ u.proto ~
+ %http `|
+ %https `&
+ ==
::
++ parse-request-line
|= url=@t
