Appearance
API call rewriting
Symptoms of API call rewriting, which maps public paths to backend paths in requests and reverses the mapping for links in answers.
The backend gets the public path (rewrite does nothing)
- Symptom: the backend logs
/api/v1/users/7instead of/internal/users/7. - Cause: no rewrite matches. Prefixes match whole segments (
/api/v1does not match/api/v10). A template matches the full path (/users/{id}does not match/users/7/orders) and never a.,..or%2esegment.methodslimits the rewrite. An earlier rewrite in the list matched first. A regex must match the whole path. - Check: the first matching rewrite wins, so read the list in order. The generated routes are named
<app>/rewrite/<name>in the Envoy configuration dump. - Fix: correct the match, or move the more specific rewrite up.
The configuration is refused: "to: ... must be an absolute path"
- Cause:
tomust start with one/and hold no.., encoded slashes or dots, query or spaces. A regextomay not put a group right after the leading slash, because a capture such as/evil.comwould make//evil.com. - Fix: put fixed text before the first group, for example
/new/\1.
The client still sees backend paths in Location or in JSON
- Cause: the answer was not rewritten. Possible reasons: the inspection service was unreachable and the application fails open (only the request side works then); the rewrite uses a
regexmatch, which is not reversible; the link's path is not the reverse of any rewrite'sto; the pointer does not name the value (/_links/*/href, or~1for a slash in a member name); the answer is notapplication/json, is compressed with an encoding that is not decoded (br, zstd), is longer than the response body limit or 4 MiB, or its JSON is cut off or invalid; or the answer has more than 256 links. - Check: the trace of the request shows
rewrite: ...changes. The counterwaap_rewrite_unmatched_totalrises for links that no rewrite maps back. - Fix: add a rewrite whose
tocovers the link's path, or correct the pointer.
The backend rejects the request after a rewrite
- Cause: the
hostis not what the backend expects, arequest_headers.setvalue is wrong, or the backend needs the original path in a header (it is not added automatically). - Fix: set
hostand the headers explicitly; userequest_headers.setfor a fixed value.
The rewrite test says "no rewrite" for a path that should match
- Cause: the test checks the active version, not unsaved edits; or one of the earlier rewrites matches first (the list is ordered); or the method list excludes the method used.
- Check: on the Rewrites page, use Test; or
waap api rewrite test -app A -path P -method M. - Fix: apply the edits first, and move the specific rewrite above the general one.
Saving rewrites is refused with "fill in exactly one"
- Cause: a rewrite has none, or more than one, of: public prefix, exact public path, template and regular expression.
- Fix: clear all but one match field of that rewrite.