We are using NGINX as a reverse proxy, it dispatches the calls from outside to our internal Java microservices:
We would like to add a special service which would serve as a "man-in-the middle", but only for the request part. It's purpose is to decorate the original request (authentication, add/modify HTTP headers, verify access rights). The "decorative tasks" involve a complicated business logic which cannot be configured on NGINX itself.
We want the service to be called as first, and then forward its response (especially the HTTP headers!) as a request to one of the microservices. Maybe also optionally to call the dispatched services with the original body, but with the HTTP headers returned from the decorator service.
When the service returns an HTTP error, it should return directly to the caller without dispatching.
The service is implemented as a Java Spring Boot application. It is a regular web service.
Is it possible to be configured in NGINX, and how?
To be clear: I am not asking about how to implement this specific service. What I need is only to know if (and how) can NGINX be configured so it calls another service before dispatching the call, and that NGINX passes the headers (and maybe also body, but not necessarily) returned from this service to the call.