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

WebClient - add option to disable chunked transfer [SPR-15914] #20468

Closed
spring-projects-issues opened this issue Aug 30, 2017 · 10 comments
Closed
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Marek Hawrylczak opened SPR-15914 and commented

Currently all requests except GET and HEAD are using transfer-encoding: chunked. There is no way to disable it, thus is not possible to call a network device that cannot support chunked transfer.


Affects: 5.0 RC3

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

The chunked transfer-encoding headers is coming from Reactor Netty, the underlying HTTP library. There is an open issue to add a global option for disabling it. Once there, the configuration option can easily be used via this ReactorClientHttpConnector constructor.

@spring-projects-issues
Copy link
Collaborator Author

Alex commented

It seems like Reactor Netty has added the feature, but I don't still find the option in ReactorClientHttpConnector constructor now. Is there any plan to support it or am I missing something?

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

Alex It has been added in the 0.8.x branch, while Spring Framework is on 0.7. We will upgrade to 0.8.x as part of the 5.1 cycle.

In the mean time, I've asked for that feature to be back ported to 0.7, see my comment on the linked issue.

@spring-projects-issues
Copy link
Collaborator Author

Simon commented

It would be really nice to be able to use WebClient for communicating with resources that dont support chunked  encoding and to avoid adding additional 3rd party dependencies for just doing that. 

@spring-projects-issues
Copy link
Collaborator Author

Simon commented

It would also be nice to be able to configure it using the WebClient.Builder without the need to use the reactor.netty.http.client.HttpClient

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.0 RC4 milestone Jan 11, 2019
@Tetradeus
Copy link

Tetradeus commented Oct 2, 2020

Even when setting the Content-Length header at WebClient Level, this one is not passed to Netty at "configured" state, and Netty keeps chunking.

@vaibsgharge
Copy link

Any update on this issue, please? I'm setting webclient.contentLength() explicitly still the response is getting chunked.

@rstoyanchev
Copy link
Contributor

I don't think there is anything to update. According to the Javadoc of HttpClient:

 * {@code Transfer-Encoding: chunked} will be applied for those HTTP methods for which
 * a request body is expected. {@code Content-Length} provided via request headers
 * will disable {@code Transfer-Encoding: chunked}.

In other words, this is in Reactor Netty and unless WebClient is somehow not passing the header, I don't see how it could be related to it.

@jmini
Copy link

jmini commented Oct 10, 2022

I found an interesting pointer:

If it is of type Mono, then spring-reactor-netty will calculate the content length and send a FullHttpMessage. If it is of type Flux, it will consider this as a chunked content and thus we will not calculate the content length.

source: https://stackoverflow.com/a/57891001

@yazinnnn
Copy link

so, is there any way to disable chunked transfer or calculate encoded multipart/form-data part's content-length when using declare http interface ?

e.g.

@HttpExchange("/V1.0")
interface Client {

    @PostExchange("upload")
    fun postFile(
      @RequestPart file: Resource, 
      //@RequestHeader("Content-Length") contentLength: Int
    ): Mono<String>

}

how can i set the correct content length header?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

7 participants