Skip to content
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

Register default function as coalesce alias #356

Merged
merged 4 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

Unreleased changes are available as `avenga/couper:edge` container.

* **Added**
* Register `default` function as `coalesce` alias ([#345](https://github.com/avenga/couper/issues/345))
afflerbach marked this conversation as resolved.
Show resolved Hide resolved

---

## [1.5](https://github.com/avenga/couper/releases/tag/1.5)
Expand Down
2 changes: 1 addition & 1 deletion docs/REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ To access the HTTP status code of the `default` response use `backend_responses.
| :----------------------------- | :-------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------- | :--------------------------------------------------- |
| `base64_decode` | string | Decodes Base64 data, as specified in RFC 4648. | `encoded` (string) | `base64_decode("Zm9v")` |
| `base64_encode` | string | Encodes Base64 data, as specified in RFC 4648. | `decoded` (string) | `base64_encode("foo")` |
| `coalesce` | | Returns the first of the given arguments that is not null. | `arg...` (various) | `coalesce(request.cookies.foo, "bar")` |
| `default` | string | Returns the first of the given arguments that is not null. | `arg...` (various) | `default(request.cookies.foo, "bar")` |
afflerbach marked this conversation as resolved.
Show resolved Hide resolved
| `json_decode` | various | Parses the given JSON string and, if it is valid, returns the value it represents. | `encoded` (string) | `json_decode("{\"foo\": 1}")` |
| `json_encode` | string | Returns a JSON serialization of the given value. | `val` (various) | `json_encode(request.context.myJWT)` |
| `jwt_sign` | string | jwt_sign creates and signs a JSON Web Token (JWT) from information from a referenced [JWT Signing Profile Block](#jwt-signing-profile-block) (or [JWT Block](#jwt-block) with `signing_ttl`) and additional claims provided as a function parameter. | `label` (string), `claims` (object) | `jwt_sign("myJWT")` |
Expand Down
1 change: 1 addition & 0 deletions eval/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ func newFunctionsMap() map[string]function.Function {
"base64_decode": lib.Base64DecodeFunc,
"base64_encode": lib.Base64EncodeFunc,
"coalesce": lib.CoalesceFunc,
"default": lib.CoalesceFunc,
"json_decode": stdlib.JSONDecodeFunc,
"json_encode": stdlib.JSONEncodeFunc,
"merge": lib.MergeFunc,
Expand Down
1 change: 1 addition & 0 deletions server/http_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3305,6 +3305,7 @@ func TestFunctions(t *testing.T) {
for _, tc := range []testCase{
{"merge", "/v1/merge", map[string]string{"X-Merged-1": "{\"foo\":[1,2]}", "X-Merged-2": "{\"bar\":[3,4]}", "X-Merged-3": "[\"a\",\"b\"]"}, http.StatusOK},
{"coalesce", "/v1/coalesce?q=a", map[string]string{"X-Coalesce-1": "/v1/coalesce", "X-Coalesce-2": "default", "X-Coalesce-3": "default", "X-Coalesce-4": "default"}, http.StatusOK},
{"default", "/v1/default?q=a", map[string]string{"X-Default-1": "/v1/default", "X-Default-2": "default", "X-Default-3": "default", "X-Default-4": "default"}, http.StatusOK},
} {
t.Run(tc.path[1:], func(subT *testing.T) {
helper := test.New(subT)
Expand Down
11 changes: 11 additions & 0 deletions server/testdata/integration/functions/01_couper.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,16 @@ server "api" {
}
}
}

endpoint "/default" {
response {
headers = {
x-default-1 = default(request.path, "default")
x-default-2 = default(request.cookies.undef, "default")
x-default-3 = default(request.query.q[1], "default")
x-default-4 = default(request.cookies.undef, request.query.q[1], "default", request.path)
}
}
}
}
}