-
Notifications
You must be signed in to change notification settings - Fork 3.4k
ModifyRequestBodyGatewayFilterFactory creates Content-Type header even when there is no body. #3242
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
Comments
I suppose we could condition the setting of a different content type only if content length is greater than 0 here Lines 86 to 88 in 67b612d
|
Hi can I work on this? |
It's been assigned to you |
@spencergibb We don't know anything about the actual content length before the body I reproduced it, wrote a quick fix, but then realized @Nullable
private MediaType updateContentType(ReactiveHttpOutputMessage message, @Nullable MediaType mediaType) {
MediaType result = message.getHeaders().getContentType();
if (result != null) {
return result;
}
MediaType fallback = this.defaultMediaType;
result = (useFallback(mediaType, fallback) ? fallback : mediaType);
if (result != null) {
result = addDefaultCharset(result, fallback);
message.getHeaders().setContentType(result);
}
return result;
} I figure it means it's I created a separate issue for the blocker as well as a PR that fixes it. I hope it will be merged soon |
This comment has been minimized.
This comment has been minimized.
@spencergibb my PR was merged a few days ago. As soon as we're past an upcoming 6.2M2 milestone, I'm all good to submit a fix for this issue (as long as @vasantteja doesn't mind as an assignee). Feel free to tag me when it's the time |
@NadChel any update on fixing this issue? |
@spencergibb was the Spring dependency updated yet (the one containing |
Can I work on this issue because it's still opened? |
I think it's been fixed since 00b862c with spring framework 6.2. I upgraded the dependency on the demo project from 4.1.1 to 4.2.0 and the content-type header no longer exists in the forwarded request. see branch @NadChel @spencergibb |
Describe the bug
Using
ModifyRequestBodyGatewayFilterFactory
with a rewrite function that returnsMono.empty();
, a content-type header is still added to the downstream request which bricks the downstream API contract.Reproduced on spring cloud gateway 4.1.1 and 3.1.1
Expected behaviour
When the return value is
Mono.empty()
(cannot benull
/Mono.just(null)
), thecontent-type
header should not be set. This ensures bodyless requests are not assigned the wrong headers.Sample
Received request:
Modified request:
Note there is a
Content-Type: text/plainlcharset=UTF-8
header in the downstream request.RewriteFunction
I've made a mre with the version 4.1.1, but this behaviour also exists in the 3.x versions. The repo is as below:
https://github.com/HarryHsuzx/scgRewriteFunctionContentTypeMRE/blob/master/src/main/resources/application.yml
The text was updated successfully, but these errors were encountered: