unit
unit copied to clipboard
Chained route actions for a request processing pipeline
Action chaining enables a route action to be configured as an array of action objects.
{
"routes": [
{
"action": [
{
"pass": "applications/auth_check"
},
{
"pass": "applications/my_app"
}
]
}
]
}
The client request is passed in sequence to every action in the array provided a 2xx
response is returned from each action. Any non-2xx
responses are returned to the client.
The initial implementation will support a variety of authentication use cases, including the equivalent of nginx auth_request
.
Hello, is there a rough timeline/planned version for this proposal?
Not yet but as this is a mayor enhancement we will have a chat about internally and discuss a potential implementation. We will update the timeline asap within the next weeks.
Nice feature to combine chain of try_files for example to deliver static assets by checking for presence of css.brotli/css.gz/.css files
Nice feature to combine chain of try_files for example to deliver static assets by checking for presence of css.brotli/css.gz/.css files
@andypost , this issue (chained routes) is to allow for Unit applications
to be pipelined.
For your use case, you can pretty much do this now (as of 1.31) by combining a few features:
- Match on
Accept-Encoding
request header - Look for the relevant filename extension on disk for compressed versions
- Add the correct
Content-Encoding
response header on a match - Fallback to a regular
share
if no match
[
{
"match": {
"headers": {
"Accept-Encoding": "*gzip*"
}
},
"action": {
"share": "/www/html${uri}.gz",
"response_headers": {
"Content-Encoding": "gzip"
},
"fallback": {
"share": "/www/html$uri"
}
}
},
{
"action": {
"share": "/www/html$uri"
}
}
]
This routes
configuration works pretty well, with a couple of snags:
- Doesn't work for index files (needs an explicit filename in the URI)
- The
Content-Type
response header is missing (because the .gz filename doesn't match a MIME type), although browsers don't mind because they do their own filename-to-type mapping.