Merge pull request #1187 from urbit/change-host-matching

Change host matching so ~ will match any inbound.
This commit is contained in:
Elliot Glaysher 2019-06-03 15:04:04 -07:00 committed by GitHub
commit 15363bbcad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 8 deletions

View File

@ -639,6 +639,23 @@
%- flop
|- ^- tape
?:(=(0 a) ~ [(add '0' (mod a 10)) $(a (div a 10))])
:: +host-matches: %.y if the site :binding should be used to handle :host
::
++ host-matches
|= [binding=(unit @t) host=(unit @t)]
^- ?
:: if the binding allows for matching anything, match
::
?~ binding
%.y
:: if the host is ~, that means we're trying to bind nothing to a real
:: binding. fail.
::
?~ host
%.n
:: otherwise, do a straight comparison
::
=(u.binding u.host)
:: +path-matches: returns %.y if :prefix is a prefix of :full
::
++ path-matches
@ -1632,7 +1649,8 @@
::
:: If we are missing a 'Host:' header, if that header is a raw IP
:: address, or if the 'Host:' header refers to [our].urbit.org, we want
:: to return ~ which is the binding for our Urbit identity.
:: to return ~ which means we're unidentified and will match against any
:: wildcard matching.
::
:: Otherwise, return the site given.
::
@ -1676,17 +1694,19 @@
?~ bindings
[%four-oh-four ~]
::
?: (path-matches path.binding.i.bindings parsed-url)
?: ?& (host-matches site.binding.i.bindings raw-host)
(path-matches path.binding.i.bindings parsed-url)
==
action.i.bindings
::
$(bindings t.bindings)
--
::
::
++ parse-request-line
|= url=@t
^- [[ext=(unit @ta) site=(list @t)] args=(list [key=@t value=@t])]
(fall (rush url ;~(plug apat:de-purl:html yque:de-purl:html)) [[~ ~] ~])
::
::
++ parse-request-line
|= url=@t
^- [[ext=(unit @ta) site=(list @t)] args=(list [key=@t value=@t])]
(fall (rush url ;~(plug apat:de-purl:html yque:de-purl:html)) [[~ ~] ~])
--
:: end the =~
::

View File

@ -105,6 +105,30 @@
results4
==
::
++ test-host-matching
;: weld
::
%+ expect-eq
!>(%.y)
!>((host-matches:http-server-gate ~ `'example.com'))
::
%+ expect-eq
!>(%.y)
!>((host-matches:http-server-gate ~ ~))
::
%+ expect-eq
!>(%.n)
!>((host-matches:http-server-gate `'example.com' ~))
::
%+ expect-eq
!>(%.y)
!>((host-matches:http-server-gate `'example.com' `'example.com'))
::
%+ expect-eq
!>(%.n)
!>((host-matches:http-server-gate `'example.com' `'blah.com'))
==
::
++ test-cant-remove-other-ducts-binding
::
=^ results1 http-server-gate