Add an Optional getter for the contentLength and a new fromContentProvider method in RequestBody #2370
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add an Optional getter for the
contentLength
a newfromContentProvider
method allowing contentLength in classRequestBody
to be null.Description
Some APIs don't require the
Content-Length
header and support receiving the request body using Transfer-Encoding: chunked. For example,Lex postContent
.Currently,
RequestBody
returns a primitive long from itscontentLength()
method, and all static constructors onRequestBody
require a content length parameter if it can't be determined automatically; e.g.fromInputStream
.With the optional getter we can omit the
content-length
fromRequestBody
so that we can fully use service operations that don't require it upfront; especially in cases where the content length can't be determined beforehand.Also, with the newly added
fromContentProvider
method theRequestBody
can be created with anull
content-length when thecontent-length
is not needed.Testing
Corresponding unit test is added.