You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2020/08/05 09:01:21 UTC

[httpcomponents-core] branch master updated (0c8886c -> a3870ef)

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git.


    omit 0c8886c  Revert "HTTPCORE-642: Implement ConnectionFactory fluent builders"
    omit d2afcc6  HTTPCORE-642: Implement ConnectionFactory fluent builders
     new a3870ef  Revert "Improved handling of early response messages by the classic client protocol handler"

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (0c8886c)
            \
             N -- N -- N   refs/heads/master (a3870ef)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../hc/core5/http/impl/io/BHttpConnectionBase.java |  2 +-
 .../http/impl/io/DefaultBHttpClientConnection.java | 68 +---------------------
 .../http/impl/io/ResponseOutOfOrderException.java  | 41 -------------
 .../java/org/apache/hc/core5/util/Timeout.java     |  5 --
 .../impl/io/TestDefaultBHttpClientConnection.java  |  8 ---
 5 files changed, 4 insertions(+), 120 deletions(-)
 delete mode 100644 httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ResponseOutOfOrderException.java


[httpcomponents-core] 01/01: Revert "Improved handling of early response messages by the classic client protocol handler"

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git

commit a3870ef2808cd78c9c3d849df6ee56b2ef8a4f95
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Wed Aug 5 10:54:56 2020 +0200

    Revert "Improved handling of early response messages by the classic client protocol handler"
    
    This reverts commit 66375912
---
 .../hc/core5/http/impl/io/BHttpConnectionBase.java |  2 +-
 .../http/impl/io/DefaultBHttpClientConnection.java | 68 +---------------------
 .../http/impl/io/ResponseOutOfOrderException.java  | 41 -------------
 .../java/org/apache/hc/core5/util/Timeout.java     |  5 --
 .../impl/io/TestDefaultBHttpClientConnection.java  |  8 ---
 5 files changed, 4 insertions(+), 120 deletions(-)

diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java
index 4ffae0e..4d8a80c 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java
@@ -294,7 +294,7 @@ class BHttpConnectionBase implements BHttpConnection {
             return true;
         }
         try {
-            final int bytesRead = fillInputBuffer(Timeout.ONE_MILLISECOND);
+            final int bytesRead = fillInputBuffer(Timeout.ofMilliseconds(1));
             return bytesRead < 0;
         } catch (final SocketTimeoutException ex) {
             return false;
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnection.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnection.java
index 6994ec5..dd5c1e3 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnection.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnection.java
@@ -28,14 +28,11 @@
 package org.apache.hc.core5.http.impl.io;
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.Socket;
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CharsetEncoder;
 
-import javax.net.ssl.SSLSocket;
-
 import org.apache.hc.core5.http.ClassicHttpRequest;
 import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.ContentLengthStrategy;
@@ -55,7 +52,6 @@ import org.apache.hc.core5.http.io.HttpMessageParserFactory;
 import org.apache.hc.core5.http.io.HttpMessageWriter;
 import org.apache.hc.core5.http.io.HttpMessageWriterFactory;
 import org.apache.hc.core5.util.Args;
-import org.apache.hc.core5.util.Timeout;
 
 /**
  * Default implementation of {@link HttpClientConnection}.
@@ -153,64 +149,8 @@ public class DefaultBHttpClientConnection extends BHttpConnectionBase
         if (len == ContentLengthStrategy.UNDEFINED) {
             throw new LengthRequiredException();
         }
-
-        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();
-
-                    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();
-                            }
-                        }
-                    }
-
-                    @Override
-                    public void write(final byte[] b) throws IOException {
-                        totalBytes += b.length;
-                        checkForEarlyResponse();
-                        socketOutputStream.write(b);
-                    }
-
-                    @Override
-                    public void write(final byte[] b, final int off, final int len) throws IOException {
-                        totalBytes += len;
-                        checkForEarlyResponse();
-                        socketOutputStream.write(b, off, len);
-                    }
-
-                    @Override
-                    public void write(final int b) throws IOException {
-                        totalBytes++;
-                        checkForEarlyResponse();
-                        socketOutputStream.write(b);
-                    }
-
-                    @Override
-                    public void flush() throws IOException {
-                        socketOutputStream.flush();
-                    }
-
-                    @Override
-                    public void close() throws IOException {
-                        socketOutputStream.close();
-                    }
-
-                }, entity.getTrailers())) {
+        try (final OutputStream outStream = createContentOutputStream(len, this.outbuffer, socketHolder.getOutputStream(), entity.getTrailers())) {
             entity.writeTo(outStream);
-        } catch (final ResponseOutOfOrderException ex) {
-            if (len > 0) {
-                this.consistent = false;
-            }
         }
     }
 
@@ -229,13 +169,11 @@ public class DefaultBHttpClientConnection extends BHttpConnectionBase
         }
         final long len = this.outgoingContentStrategy.determineLength(request);
         if (len == ContentLengthStrategy.CHUNKED) {
-            try (final OutputStream outStream = createContentOutputStream(
-                    len, this.outbuffer, socketHolder.getOutputStream(), entity.getTrailers())) {
+            try (final OutputStream outStream = createContentOutputStream(len, this.outbuffer, socketHolder.getOutputStream(), entity.getTrailers())) {
                 // just close
             }
         } else if (len >= 0 && len <= 1024) {
-            try (final OutputStream outStream = createContentOutputStream(
-                    len, this.outbuffer, socketHolder.getOutputStream(), null)) {
+            try (final OutputStream outStream = createContentOutputStream(len, this.outbuffer, socketHolder.getOutputStream(), null)) {
                 entity.writeTo(outStream);
             }
         } else {
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ResponseOutOfOrderException.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ResponseOutOfOrderException.java
deleted file mode 100644
index 1175712..0000000
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ResponseOutOfOrderException.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation.  For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.hc.core5.http.impl.io;
-
-import java.io.IOException;
-
-/**
- * Signals an early (out of order) response.
- */
-class ResponseOutOfOrderException extends IOException {
-
-    public ResponseOutOfOrderException() {
-        super();
-    }
-
-}
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java b/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
index b3be7bf..f6a835a 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
@@ -47,11 +47,6 @@ public class Timeout extends TimeValue {
     public static final Timeout ZERO_MILLISECONDS = Timeout.of(0, TimeUnit.MILLISECONDS);
 
     /**
-     * A one millisecond {@link Timeout}.
-     */
-    public static final Timeout ONE_MILLISECOND = Timeout.of(1, TimeUnit.MILLISECONDS);
-
-    /**
      * A disabled timeout represented as 0 {@code MILLISECONDS}.
      */
     public static final Timeout DISABLED = ZERO_MILLISECONDS;
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestDefaultBHttpClientConnection.java b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestDefaultBHttpClientConnection.java
index a69dc22..286f949 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestDefaultBHttpClientConnection.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestDefaultBHttpClientConnection.java
@@ -232,7 +232,6 @@ public class TestDefaultBHttpClientConnection {
     public void testWriteRequestHead() throws Exception {
         final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
         Mockito.when(socket.getOutputStream()).thenReturn(outStream);
-        Mockito.when(socket.getInputStream()).thenReturn(Mockito.mock(InputStream.class));
 
         conn.bind(socket);
 
@@ -253,7 +252,6 @@ public class TestDefaultBHttpClientConnection {
     public void testWriteRequestEntityWithContentLength() throws Exception {
         final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
         Mockito.when(socket.getOutputStream()).thenReturn(outStream);
-        Mockito.when(socket.getInputStream()).thenReturn(Mockito.mock(InputStream.class));
 
         conn.bind(socket);
 
@@ -277,7 +275,6 @@ public class TestDefaultBHttpClientConnection {
     public void testWriteRequestEntityChunkCoded() throws Exception {
         final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
         Mockito.when(socket.getOutputStream()).thenReturn(outStream);
-        Mockito.when(socket.getInputStream()).thenReturn(Mockito.mock(InputStream.class));
 
         conn.bind(socket);
 
@@ -302,7 +299,6 @@ public class TestDefaultBHttpClientConnection {
     public void testWriteRequestEntityNoContentLength() throws Exception {
         final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
         Mockito.when(socket.getOutputStream()).thenReturn(outStream);
-        Mockito.when(socket.getInputStream()).thenReturn(Mockito.mock(InputStream.class));
 
         conn.bind(socket);
 
@@ -320,7 +316,6 @@ public class TestDefaultBHttpClientConnection {
     public void testWriteRequestNoEntity() throws Exception {
         final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
         Mockito.when(socket.getOutputStream()).thenReturn(outStream);
-        Mockito.when(socket.getInputStream()).thenReturn(Mockito.mock(InputStream.class));
 
         conn.bind(socket);
 
@@ -342,7 +337,6 @@ public class TestDefaultBHttpClientConnection {
     public void testTerminateRequestChunkedEntity() throws Exception {
         final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
         Mockito.when(socket.getOutputStream()).thenReturn(outStream);
-        Mockito.when(socket.getInputStream()).thenReturn(Mockito.mock(InputStream.class));
 
         conn.bind(socket);
 
@@ -370,7 +364,6 @@ public class TestDefaultBHttpClientConnection {
     public void testTerminateRequestContentLengthShort() throws Exception {
         final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
         Mockito.when(socket.getOutputStream()).thenReturn(outStream);
-        Mockito.when(socket.getInputStream()).thenReturn(Mockito.mock(InputStream.class));
 
         conn.bind(socket);
 
@@ -397,7 +390,6 @@ public class TestDefaultBHttpClientConnection {
     public void testTerminateRequestContentLengthLong() throws Exception {
         final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
         Mockito.when(socket.getOutputStream()).thenReturn(outStream);
-        Mockito.when(socket.getInputStream()).thenReturn(Mockito.mock(InputStream.class));
 
         conn.bind(socket);