Skip to content

Commit

Permalink
Merge pull request #356 from kos-maverik/master
Browse files Browse the repository at this point in the history
Register default function as coalesce alias
  • Loading branch information
afflerbach committed Oct 26, 2021
2 parents 8e4d7c7 + 0541eb2 commit 81c7d8f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
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 ([#356](https://github.com/avenga/couper/pull/356))

---

## [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")` |
| `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)
}
}
}
}
}

0 comments on commit 81c7d8f

Please sign in to comment.