micronaut-projects / micronaut-core

Micronaut Application Framework
http://micronaut.io
Apache License 2.0
6k stars 1.04k forks source link

CompletableFuture endpoint with a redirect response returns a 200 #10917

Open timyates opened 2 weeks ago

timyates commented 2 weeks ago

Expected Behavior

Prior to Micronaut 4, the following returned a 307 response

    MutableHttpResponse createResponse() {
        final override = Map.of(
                'Location', 'http://foo.com',
                'Content-Length', '0',
                'Connection', 'close' )
        return HttpResponse
                .status(HttpStatus.valueOf(307))
                .headers(toMutableHeaders(override))
    }

    @Get("/redirect/fail")
    CompletableFuture<MutableHttpResponse> redirectFail() {
        CompletableFuture.completedFuture(createResponse())
    }

Actual Behaviour

Instead of the expected 307 response, we get a 200 response.

If we add a body to the response by changing the above example to the following, we get 307 as expected

        return HttpResponse
                .status(HttpStatus.valueOf(307))
                .body('')
                .headers(toMutableHeaders(override))

I suspect the issue is here as supplying a body to the response object makes it return the correct status code.

I guess any custom headers are also currently being dropped 🤔

The reproducer is in Groovy, but I don't think it's a Groovy issue 🤔

Steps To Reproduce

Clone https://github.com/munishchouhan/temporaryredirectproblem Run the tests

Environment Information

No response

Example Application

https://github.com/munishchouhan/temporaryredirectproblem

Version

4.5.0