micronaut-core
micronaut-core copied to clipboard
ResponseFilter of ClientFilter does not support MutableHttpResponse
Expected Behavior
The content-type of response of httpclient (HttpBinClient) is rewrited from application/json
to text/plain
@ResponseFilter
fun filter(request: MutableHttpRequest<*>, response: MutableHttpResponse<*>) {
response.headers.set("content-type", "text/plain")
}
ps My goal is to fix a header of declarative httpclient's response. Some remote service returns broken content-type, I guess the best way to fix it is ResponseFilter of ClientFilter.
Actual Behaviour
The exception is raised:
Unexpected error occurred: class io.micronaut.http.client.netty.FullNettyClientHttpResponse cannot be cast to class io.micronaut.http.MutableHttpResponse (io.micronaut.http.client.netty.FullNettyClientHttpResponse and io.micronaut.http.MutableHttpResponse are in unnamed module of loader 'app')
java.lang.ClassCastException: class io.micronaut.http.client.netty.FullNettyClientHttpResponse cannot be cast to class io.micronaut.http.MutableHttpResponse (io.micronaut.http.client.netty.FullNettyClientHttpResponse and io.micronaut.http.MutableHttpResponse are in unnamed module of loader 'app')
at com.github.mn.$HttpBinFilter$Definition$Exec.dispatch(Unknown Source)
at io.micronaut.context.AbstractExecutableMethodsDefinition$DispatchedExecutableMethod.invokeUnsafe(AbstractExecutableMethodsDefinition.java:447)
at io.micronaut.http.filter.FilterRunner$FilterMethod.filter0(FilterRunner.java:640)
at io.micronaut.http.filter.FilterRunner$FilterMethod.filter(FilterRunner.java:629)
...
Steps To Reproduce
- Run the project
- Perform request
curl -v -X GET "http://localhost:8080/json"
- See stacktraces in application logs:
Unexpected error occurred: class io.micronaut.http.client.netty.FullNettyClientHttpResponse cannot be cast to class io.micronaut.http.MutableHttpResponse (io.micronaut.http.client.netty.FullNettyClientHttpResponse and io.micronaut.http.MutableHttpResponse are in unnamed module of loader 'app')
Environment Information
OS: Windows 11 21H2 x64 JVM: 17.0.1 (Oracle Corporation 17.0.1+12-39) Micronaut 4.1.5: Gradle, Kotlin, Spock, Reactor, Netty
Example Application
https://github.com/eratolekov/micronaut-responsefilter-bug
Version
4.1.5