This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 119
Always add Content-Length header #648
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,9 @@ public String getFieldValue(String s) { | |
HttpRequest httpRequest = httpRequestRunnable.createHttpRequest(); | ||
String expectedUrl = ENDPOINT + "name/tree_frog" + "?requestId=request57"; | ||
Truth.assertThat(httpRequest.getUrl().toString()).isEqualTo(expectedUrl); | ||
Truth.assertThat(httpRequest.getHeaders().getContentLength()) | ||
.isEqualTo(httpRequest.getContent().getLength()); | ||
Truth.assertThat(httpRequest.getHeaders().getContentLength()).isGreaterThan((long) 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed this . |
||
|
||
OutputStream outputStream = new PrintableOutputStream(); | ||
httpRequest.getContent().writeTo(outputStream); | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little bit odd place for this. Few line earlier (L113) we already call the actual enhancers, but then, right after that we create one more on the fly just to call it once. Ideally we would want to have this enhancer as a default one, created in
InstantiatingHttpJsonChannelProvider#createChannel()
method (together with the other, static enhancers). The difference between this enhancer and the other ones (returned bygetHeaderEnhancers()
is that the other ones are static (do not depend on the actual body of the request) and this one is dynamic (does depend on the body, specifically on the size of the body).I would suggest changing the
HttpJsonHeaderEnhancer
interface (it is@BetaApi
, so should be ok) to accept the actualHttpRequest
instead ofHttpHeaders
object.Then create two enhancer implementations, one, which will be doing static headers (i.e. one single enhancer for all static headers) and one for dynamic headers, and instantiate both of those in
InstantiatingHttpJsonChannelProvider#createChannel()
.Then here, just call the enhancers normally in the loop (like on line 112), but pass the
httpRequest
as an argument (instead ofhttpRequest.getHeaders()
as it is done now).With the above suggestion in place, the HeaderEnhancers get their fair chunk of responsibility: setting headers (bot static and dynamic). Now they seem like be just doing a simple call to
HttpHeadersUtils.setHeader()
which is too little to justify existence of the small "family" of classes (the Enhancers class hierarchy).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed all of this.