Micronaut Get raw HttpRequest

490 Views Asked by At

My app gets deployed to customer sites. Some customers have proxies that perform authentication of users then forward a particular HTTP cookie/header. These can be of custom format. I want to be able to provide one micronaut URL e.g. /customAuth That a customer can provide an override for Allowing them to forward the request from their proxy and handle it themselves.

Unfortunately this is proving very hard in micronaut as:

  1. It inists I specify @Post/@Get or what the HTTP method should be.
  2. It parses the headers/body before forwarding.

What I really need is:

@All(/customAuth) HttpResponse customAuth(String fullRawHttpRequestWithHeaders) {

I've seen this question on raaw body (Get raw HttpRequest body in Micronaut). I share their problem that I don't even know if there will be a body.

I've seen this question on getting headers: How to get full list of request headers in Micronaut

It seems micronaut really just does NOT want to give raw access which is what some people really need, e.g. in my case.

Is this the case?

1

There are 1 best solutions below

1
Ryan Hamilton On

One solution would be to recreate the raaw requests as best as possible .e.g

    StringBuilder ms = new StringBuilder();
    // add cookies
    Map<String, Cookie> m = req.getCookies().asMap();
    m.forEach((t, u) -> ms.append(t + ":" + u.getValue()));
        
    // add headers
    req.getHeaders().asMap().entrySet().
    .. add body

This seems a huge waste of effort, inefficient and likely to go wrong.