Summary
Hi,
I'm extracting POST request boy in WebFilter to check something. But when the request actually reaches controller API, it seems request body is getting consumed already. All requests are failing with 400 BAD REQUEST.
Actual Behavior
I'm consuming post body as input stream and the body is not getting retained when the request finally hits controller API.
Expected Behavior
Is there a way to retain the body and read it again in controller. Reading body in webfilter is necessary due to the pre-checks I've to perform.
Configuration
Version
Sample
exchange.getRequest().getBody().next().flatMap(body -> {
try {
function(mapper.readValue(body., typeRef).getOrDefault("project", "").toString(),));
body.asInputStream().close();
} catch (Exception e) {
logger.log(Level.SEVERE, e.getMessage());
}
Comment From: eleftherias
Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.
Comment From: eleftherias
The issue you're seeing occurs because the body is a DataBuffer, which means it can only be consumed once.
This StackOverflow question seems similar to what you are asking https://stackoverflow.com/questions/47182961/copy-of-the-request-response-body-on-a-spring-reactive-app.