Skip to content

VirtualServerRoute: action.return headers #2420

@andrew-s

Description

@andrew-s

Is your feature request related to a problem? Please describe.
There are situations when using VirtualServerRoute's that you want to return a header when you use action.return, an example of this is shifting OPTIONS method requests into Nginx instead of the application (e.g. if you're pre-building ingresses via a helm chart) and you need to return the headers in an action.return - currently this is unsupported

Describe the solution you'd like
Strangely, headers can be returned in the ErrorPage.return ( https://docs.nginx.com/nginx-ingress-controller/configuration/virtualserver-and-virtualserverroute-resources/#errorpagereturnheader ) - essentially this same mechanism can be used for action.return and then makes these consistent since they're almost identical. I also don't believe this an nginx.conf limitation.

An example and use case of what this might look like;

       - conditions:
         - variable: $request_method
           value: "OPTIONS"
         action:
           return:
            code: 200
            body: "OK"
             headers:
             - name: Access-Control-Allow-Origin
               value: "*"

Describe alternatives you've considered
In theory, it looks like you'd be able to do this with the location snippet support but it seems like that goes against the conditional match patterns that VirtualServer brings to the table, e.g. you could return in the http snippet before the conditional match happens and there are some situations where you may want to do this (such as conditionals on other variables).

Additional context
I'd be happy to open a PR and start working on this if it's something that would be accept into the spec

Update: It looks like there's a bug in the location snippet whereby it doesn't get sent to the default routes so this doesn't work, I hadn't realised that default routes are sent through the ErrorPages struct with a default 418 code which then gets remapped, this looks to be causing issues with using location snippets here. The true workaround here (and is not great) is to create a service in the cluster that always returns "OK" and proxy pass that upstream until headers can be returned in action.return. So to be clear, snippets do not work here.

Aha! Link: https://nginx.aha.io/features/IC-413

Metadata

Metadata

Assignees

Labels

backlogPull requests/issues that are backlog itemsproposalAn issue that proposes a feature request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions