New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
caddyfile: Support for raw token values, improve map
, expression
#4643
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
114 changes: 114 additions & 0 deletions
114
caddytest/integration/caddyfile_adapt/expression_quotes.txt
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,114 @@ | ||
example.com | ||
|
||
@a expression {http.error.status_code} == 400 | ||
abort @a | ||
|
||
@b expression {http.error.status_code} == "401" | ||
abort @b | ||
|
||
@c expression {http.error.status_code} == `402` | ||
abort @c | ||
|
||
@d expression "{http.error.status_code} == 403" | ||
abort @d | ||
|
||
@e expression `{http.error.status_code} == 404` | ||
abort @e | ||
---------- | ||
{ | ||
"apps": { | ||
"http": { | ||
"servers": { | ||
"srv0": { | ||
"listen": [ | ||
":443" | ||
], | ||
"routes": [ | ||
{ | ||
"match": [ | ||
{ | ||
"host": [ | ||
"example.com" | ||
] | ||
} | ||
], | ||
"handle": [ | ||
{ | ||
"handler": "subroute", | ||
"routes": [ | ||
{ | ||
"handle": [ | ||
{ | ||
"abort": true, | ||
"handler": "static_response" | ||
} | ||
], | ||
"match": [ | ||
{ | ||
"expression": "{http.error.status_code} == 400" | ||
} | ||
] | ||
}, | ||
{ | ||
"handle": [ | ||
{ | ||
"abort": true, | ||
"handler": "static_response" | ||
} | ||
], | ||
"match": [ | ||
{ | ||
"expression": "{http.error.status_code} == \"401\"" | ||
} | ||
] | ||
}, | ||
{ | ||
"handle": [ | ||
{ | ||
"abort": true, | ||
"handler": "static_response" | ||
} | ||
], | ||
"match": [ | ||
{ | ||
"expression": "{http.error.status_code} == `402`" | ||
} | ||
] | ||
}, | ||
{ | ||
"handle": [ | ||
{ | ||
"abort": true, | ||
"handler": "static_response" | ||
} | ||
], | ||
"match": [ | ||
{ | ||
"expression": "{http.error.status_code} == 403" | ||
} | ||
] | ||
}, | ||
{ | ||
"handle": [ | ||
{ | ||
"abort": true, | ||
"handler": "static_response" | ||
} | ||
], | ||
"match": [ | ||
{ | ||
"expression": "{http.error.status_code} == 404" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"terminal": true | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
caddytest/integration/caddyfile_adapt/map_with_raw_types.txt
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,107 @@ | ||
example.com | ||
|
||
map {host} {my_placeholder} {magic_number} { | ||
# Should output boolean "true" and an integer | ||
example.com true 3 | ||
|
||
# Should output a string and null | ||
foo.example.com "string value" | ||
|
||
# Should output two strings (quoted int) | ||
(.*)\.example.com "${1} subdomain" "5" | ||
|
||
# Should output null and a string (quoted int) | ||
~.*\.net$ - `7` | ||
|
||
# Should output a float and the string "false" | ||
~.*\.xyz$ 123.456 "false" | ||
|
||
# Should output two strings, second being escaped quote | ||
default "unknown domain" \""" | ||
} | ||
---------- | ||
{ | ||
"apps": { | ||
"http": { | ||
"servers": { | ||
"srv0": { | ||
"listen": [ | ||
":443" | ||
], | ||
"routes": [ | ||
{ | ||
"match": [ | ||
{ | ||
"host": [ | ||
"example.com" | ||
] | ||
} | ||
], | ||
"handle": [ | ||
{ | ||
"handler": "subroute", | ||
"routes": [ | ||
{ | ||
"handle": [ | ||
{ | ||
"defaults": [ | ||
"unknown domain", | ||
"\"" | ||
], | ||
"destinations": [ | ||
"{my_placeholder}", | ||
"{magic_number}" | ||
], | ||
"handler": "map", | ||
"mappings": [ | ||
{ | ||
"input": "example.com", | ||
"outputs": [ | ||
true, | ||
3 | ||
] | ||
}, | ||
{ | ||
"input": "foo.example.com", | ||
"outputs": [ | ||
"string value", | ||
null | ||
] | ||
}, | ||
{ | ||
"input": "(.*)\\.example.com", | ||
"outputs": [ | ||
"${1} subdomain", | ||
"5" | ||
] | ||
}, | ||
{ | ||
"input_regexp": ".*\\.net$", | ||
"outputs": [ | ||
null, | ||
"7" | ||
] | ||
}, | ||
{ | ||
"input_regexp": ".*\\.xyz$", | ||
"outputs": [ | ||
123.456, | ||
"false" | ||
] | ||
} | ||
], | ||
"source": "{http.request.host}" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"terminal": true | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good name choice, but
TypedVal()
also came to mind. Not sure which is better. I'm fine with this, but wanted to ask anyway to see what you thought.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Typed would be better if we supported returning somekind of struct, but I think Scalar is clearer that only scalars will be returned (for now)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, and that's what I was wondering too, if in the future we'd ever deserialize a string as a structured data type. But I can't see that happening in the near future nor do I have any idea why or what that would look like. So Scalar is fine... hopefully we don't have to change it.