carterkozak commented on a change in pull request #206:
URL:
https://github.com/apache/httpcomponents-core/pull/206#discussion_r464089770
##########
File path:
httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnection.java
##########
@@ -157,41 +198,40 @@ public void sendRequestEntity(final ClassicHttpRequest
request) throws HttpExcep
try (final OutputStream outStream = createContentOutputStream(
len, this.outbuffer, new OutputStream() {
- final boolean ssl = socketHolder.getSocket() instanceof
SSLSocket;
- final InputStream socketInputStream =
socketHolder.getInputStream();
final OutputStream socketOutputStream =
socketHolder.getOutputStream();
+ final InputStream socketInputStream =
socketHolder.getInputStream();
long totalBytes = 0;
- long chunks = -1;
- void checkForEarlyResponse() throws IOException {
- final long n = totalBytes / (8 * 1024);
- if (n > chunks) {
- chunks = n;
- if (ssl ? isDataAvailable(Timeout.ONE_MILLISECOND)
: (socketInputStream.available() > 0)) {
- throw new ResponseOutOfOrderException();
- }
+ void checkForEarlyResponse(final long totalBytesSent,
final int nextWriteSize) throws IOException {
+ if (responseOutOfOrderStrategy.checkForEarlyResponse(
+ DefaultBHttpClientConnection.this,
+ request,
+ socketInputStream,
+ totalBytesSent,
+ nextWriteSize)) {
+ throw new ResponseOutOfOrderException();
}
}
@Override
public void write(final byte[] b) throws IOException {
+ checkForEarlyResponse(totalBytes, b.length);
Review comment:
I don't think this changed behavior, previously the algorithm was:
1. accumulate the next write length with the total length
2. check for response using the updated totalBytes value
3. write to the socket
Now we do the same thing, with the minor change that we pass both the
pre-write value and the length separately, instead of the sum:
1. check for response using the previous totalBytes and write length values
2. accumulate the next write length with the total length
3. write to the socket
This OutputStream is entirely encapsulated within
`DefaultBHttpClientConnection.sendRequestEntity`. Regardless of the headers,
`totalBytes` only tracks the entity size, starting at zero. In the previous
implementation `chunks` was initialized at `-1` which forces the first write to
check for a response prior to checking the socket, even if the length is zero.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]