-
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Standardize support for header forwarding and inline headers (#560)
The immediate motivation for this change was the following issue against the Haskell implementation: #396 ... which unearthed two problems: * First, I realized that I had not yet standardized the Haskell implementation's support for forwarding custom headers This is a feature that allows transitive imports to the same domain to reuse headers (mainly to reuse authentication headers). This comes in handy when importing from private expression repositories that contain internal imports. * Second, I learned why the Haskell support for forwarding headers was broken The issue was that custom headers were being forwarded by a (referentially opaque) reference instead of being forwarded by value. Fixing this requires generalizing the `using` clause for custom headers to be able to store an arbitrary expression so that it could store the fully resolved and normalized headers. So this change bundles two logical changes: * Generalizing `using` to store an inline expression This is a useful change in its own right because now users can specify custom headers inline within the same file instead of having to provide them in a separate file. This is not a breaking change to the grammar, but it is a minor breaking change to the binary encoding. Specifically, the expression for custom headers will now be encoded as an expression and not an import, meaning that it is now wrapped in an extra `[24, ... ]` label that was previously not there before. This doesn't affect semantic integrity checks since the hashed expressions are import free. * Adding support for header forwarding if the parent/child import share the same authority and both use HTTPS I thought I had already standardized this, but apparently not! 🙂 This forwards them by value instead of by reference in order to avoid introducing the bug caught by the linked issue.
- Loading branch information
1 parent
ee528e5
commit b1f9815
Showing
12 changed files
with
133 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
https://httpbin.org/user-agent | ||
using [ { header = "User-Agent", value = "Dhall" } ] | ||
as Text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'' | ||
{ | ||
"user-agent": "Dhall" | ||
} | ||
'' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{- This test verifies that header-forwarding works correctly for relative | ||
imports within the same domain | ||
`test.dhall-lang.org` is the same as `prelude.dhall-lang.org` except that | ||
`test.dhall-lang.org` rejects all requests without a `Test` header. | ||
This test requires that the initial import to | ||
`https://test.dhall-lang.org/Bool/package.dhall` forwards the `Test` header | ||
to the transitive relative imports of `https://test.dhall-lang.org/Bool/*` in | ||
order to succeed. | ||
Note: You will need to update this test whenever the `Bool` package in the | ||
Prelude changes (sorry) | ||
-} | ||
https://test.dhall-lang.org/Bool/package.dhall | ||
using [ { header = "Test", value = "Example" } ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ and = | ||
λ(xs : List Bool) | ||
→ List/fold Bool xs Bool (λ(l : Bool) → λ(r : Bool) → l && r) True | ||
, build = | ||
λ(f : ∀(bool : Type) → ∀(true : bool) → ∀(false : bool) → bool) | ||
→ f Bool True False | ||
, even = | ||
λ(xs : List Bool) | ||
→ List/fold Bool xs Bool (λ(x : Bool) → λ(y : Bool) → x == y) True | ||
, fold = | ||
λ(b : Bool) | ||
→ λ(bool : Type) | ||
→ λ(true : bool) | ||
→ λ(false : bool) | ||
→ if b then true else false | ||
, not = | ||
λ(b : Bool) → b == False | ||
, odd = | ||
λ(xs : List Bool) | ||
→ List/fold Bool xs Bool (λ(x : Bool) → λ(y : Bool) → x != y) False | ||
, or = | ||
λ(xs : List Bool) | ||
→ List/fold Bool xs Bool (λ(l : Bool) → λ(r : Bool) → l || r) False | ||
, show = | ||
λ(b : Bool) → if b then "True" else "False" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{- The purpose of this test is to verify that the custom headers supplied to | ||
this import are not forwarded to the transitive import of | ||
https://httpbin.org/user-agent | ||
-} | ||
https://raw.githubusercontent.com/dhall-lang/dhall-lang/master/tests/import/success/customHeadersA.dhall | ||
using [ { header = "User-Agent", value = "Secret" } ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'' | ||
{ | ||
"user-agent": "Dhall" | ||
} | ||
'' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{- The language standard used to require that custom headers were provided via | ||
an external import, but was later amended to support inline headers as part | ||
of: | ||
https://github.com/dhall-lang/dhall-lang/pull/560 | ||
This test verifies that an implementation supports such inline custom headers | ||
-} | ||
|
||
https://example.com/foo using | ||
[ { header = "Authorization" | ||
, value = "token 5199831f4dd3b79e7c5b7e0ebe75d67aa66e79d4" | ||
} | ||
] |
Binary file not shown.
Binary file modified
BIN
+47 Bytes
(120%)
tests/parser/success/unit/import/parenthesizeUsingB.dhallb
Binary file not shown.
15 changes: 15 additions & 0 deletions
15
tests/typecheck/failure/customHeadersUsingBoundVariable.dhall
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{- This is a type error because the custom headers are type-checked with an | ||
empty context. This is necessary because: | ||
* import resolution precedes β-normalization | ||
* we also don't want custom headers to leak program state anyway | ||
This should fail due to the `x` within the custom header being an unbound | ||
variable | ||
-} | ||
|
||
let x = "Bar" | ||
|
||
in https://httpbin.org/headers | ||
using [ { header = "Foo", value = x } ] | ||
as Text |