Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gateway MVC ServerRequest body broken when created from another #3380

Open
mcordeiro73 opened this issue Apr 30, 2024 · 0 comments
Open

Gateway MVC ServerRequest body broken when created from another #3380

mcordeiro73 opened this issue Apr 30, 2024 · 0 comments

Comments

@mcordeiro73
Copy link

Describe the bug
When using ServerRequest.from(other) to augment a ServerRequest in a filter, a new DefaultServerRequestBuilder is returned with body = new byte[0], even if the original ServerRequest has a body. Subsequent filters then get an empty body value. It does appear that the downstream service still does get the correct body, and only other filters are affected.

Sample

Below is a very trivial sample before filter that reproduces the issue. Note: the request body does not need to be read from the original ServerRequest to reproduce this issue, I'm merely doing that in the example to illustrate the issue.

builder.before(request -> {
	ServerRequest modified;
	try {
		String requestBody = request.body(String.class);
		modified = ServerRequest.from(request)
				.header("X-CUSTOM_HEADER", "value")
				.build();
		String modifiedRequestBody = request.body(String.class);
		Assert.isTrue(StringUtils.equals(requestBody, modifiedRequestBody), "Request body should still be the same!");
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
	return modified;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant