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/10/03 10:32:20 UTC

[httpcomponents-client] branch 4.5.x updated (767b3ba -> 60f8edb)

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

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


 discard 767b3ba  Incorrect handling of malformed authority component by URIUtils#extractHost
    omit bd3be1b  Avoid updating Content-Length header in a 304 response.
    omit ed9916d  Add section for Release 4.5.13.
    omit d4592f5  Document bug fix in RN.
     new 8151d9e  Avoid updating Content-Length header in a 304 response.
     new e628b4c  Incorrect handling of malformed authority component by URIUtils#extractHost
     new 60f8edb  Updated release notes for HttpClient 4.5.13 release

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   (767b3ba)
            \
             N -- N -- N   refs/heads/4.5.x (60f8edb)

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 3 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:
 RELEASE_NOTES.txt | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)


[httpcomponents-client] 01/03: Avoid updating Content-Length header in a 304 response.

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

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

commit 8151d9e51a7e06051f2c561ff04a575261acf46d
Author: dirkhenselin <di...@vwgis.de>
AuthorDate: Tue Aug 18 12:24:22 2020 +0200

    Avoid updating Content-Length header in a 304 response.
    
    I observed the following problem: `Transfer-Encoding` and
    `Content-Length` headers should be mutually exclusive and because I use
    chunked transfer, the `Transfer-Encoding` header is set in the response
    while the `Content-Length` header is not. In case of a 304 during a
    revalidation, the header contains Content-Length=0. Probably a proxy is
    responsible for this, just like the comment "Some well-known proxies
    respond with Content-Length=0, when returning 304" in the method
    CachedHttpResponseGenerator::addMissingContentLengthHeader is saying. In
    CacheEntryUpdater::mergeHeaders the Content-Length=0 is merged into the
    cached entry, but the cached entry contains also a `Transfer-Encoding`
    header, so in the cached entry these headers aren't mutually exclusive
    anymore. Because of the `Transfer-Encoding` header the method
    CachedHttpResponseGenerator::addMissingContentLengthHeader isn't fixing
    the `Content-Length` header and Content-Length=0 causes returning null
    instead of the cached content. IMHO the `Content-Length` header should
    not be merged into the cached response in case of a 304, at least if the
    cached entry contains a `Transfer-Encoding` header.
---
 .../http/impl/client/cache/CacheEntryUpdater.java   | 10 ++++++----
 .../impl/client/cache/TestCacheEntryUpdater.java    | 21 +++++++++++++++++++++
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java b/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java
index f18c73c..e5a57cc 100644
--- a/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java
+++ b/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CacheEntryUpdater.java
@@ -111,8 +111,9 @@ class CacheEntryUpdater {
         // Remove cache headers that match response
         for (final HeaderIterator it = response.headerIterator(); it.hasNext(); ) {
             final Header responseHeader = it.nextHeader();
-            // Since we do not expect a content in a 304 response, should retain the original Content-Encoding header
-            if (HTTP.CONTENT_ENCODING.equals(responseHeader.getName())) {
+            // Since we do not expect a content in a 304 response, should retain the original Content-Encoding and Content-Length header
+            if (HTTP.CONTENT_ENCODING.equals(responseHeader.getName())
+                    || HTTP.CONTENT_LEN.equals(responseHeader.getName())) {
                 continue;
             }
             final Header[] matchingHeaders = headerGroup.getHeaders(responseHeader.getName());
@@ -133,8 +134,9 @@ class CacheEntryUpdater {
         }
         for (final HeaderIterator it = response.headerIterator(); it.hasNext(); ) {
             final Header responseHeader = it.nextHeader();
-            // Since we do not expect a content in a 304 response, should avoid updating Content-Encoding header
-            if (HTTP.CONTENT_ENCODING.equals(responseHeader.getName())) {
+            // Since we do not expect a content in a 304 response, should avoid updating Content-Encoding and Content-Length header
+            if (HTTP.CONTENT_ENCODING.equals(responseHeader.getName())
+                    || HTTP.CONTENT_LEN.equals(responseHeader.getName())) {
                 continue;
             }
             headerGroup.addHeader(responseHeader);
diff --git a/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntryUpdater.java b/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntryUpdater.java
index a0a8737..0f0ea51 100644
--- a/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntryUpdater.java
+++ b/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCacheEntryUpdater.java
@@ -260,6 +260,27 @@ public class TestCacheEntryUpdater {
         headersNotContain(updatedHeaders, "Content-Encoding", "gzip");
     }
 
+    @Test
+    public void testContentLengthIsNotAddedWhenTransferEncodingIsPresent() throws IOException {
+        final Header[] headers = {
+                new BasicHeader("Date", DateUtils.formatDate(requestDate)),
+                new BasicHeader("ETag", "\"etag\""),
+                new BasicHeader("Transfer-Encoding", "chunked")};
+
+        entry = HttpTestUtils.makeCacheEntry(headers);
+        response.setHeaders(new Header[]{
+                new BasicHeader("Last-Modified", DateUtils.formatDate(responseDate)),
+                new BasicHeader("Cache-Control", "public"),
+                new BasicHeader("Content-Length", "0")});
+
+        final HttpCacheEntry updatedEntry = impl.updateCacheEntry(null, entry,
+                new Date(), new Date(), response);
+
+        final Header[] updatedHeaders = updatedEntry.getAllHeaders();
+        headersContain(updatedHeaders, "Transfer-Encoding", "chunked");
+        headersNotContain(updatedHeaders, "Content-Length", "0");
+    }
+
     private void headersContain(final Header[] headers, final String name, final String value) {
         for (final Header header : headers) {
             if (header.getName().equals(name)) {


[httpcomponents-client] 02/03: Incorrect handling of malformed authority component by URIUtils#extractHost

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

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

commit e628b4c5c464c2fa346385596cc78e035a91a62e
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Tue Sep 29 09:37:38 2020 +0200

    Incorrect handling of malformed authority component by URIUtils#extractHost
---
 .../org/apache/http/client/utils/URIUtils.java     | 69 +++++++++-------------
 .../org/apache/http/client/utils/TestURIUtils.java |  6 +-
 2 files changed, 32 insertions(+), 43 deletions(-)

diff --git a/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java b/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java
index 8eb7667..aa3431f 100644
--- a/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java
+++ b/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java
@@ -419,56 +419,43 @@ public class URIUtils {
         if (uri == null) {
             return null;
         }
-        HttpHost target = null;
         if (uri.isAbsolute()) {
-            int port = uri.getPort(); // may be overridden later
-            String host = uri.getHost();
-            if (host == null) { // normal parse failed; let's do it ourselves
+            if (uri.getHost() == null) { // normal parse failed; let's do it ourselves
                 // authority does not seem to care about the valid character-set for host names
-                host = uri.getAuthority();
-                if (host != null) {
+                if (uri.getAuthority() != null) {
+                    String content = uri.getAuthority();
                     // Strip off any leading user credentials
-                    final int at = host.indexOf('@');
-                    if (at >= 0) {
-                        if (host.length() > at+1 ) {
-                            host = host.substring(at+1);
-                        } else {
-                            host = null; // @ on its own
-                        }
+                    int at = content.indexOf('@');
+                    if (at != -1) {
+                        content = content.substring(at + 1);
                     }
-                    // Extract the port suffix, if present
-                    if (host != null) {
-                        final int colon = host.indexOf(':');
-                        if (colon >= 0) {
-                            final int pos = colon + 1;
-                            int len = 0;
-                            for (int i = pos; i < host.length(); i++) {
-                                if (Character.isDigit(host.charAt(i))) {
-                                    len++;
-                                } else {
-                                    break;
-                                }
-                            }
-                            if (len > 0) {
-                                try {
-                                    port = Integer.parseInt(host.substring(pos, pos + len));
-                                } catch (final NumberFormatException ex) {
-                                }
-                            }
-                            host = host.substring(0, colon);
+                    final String scheme = uri.getScheme();
+                    final String hostname;
+                    final int port;
+                    at = content.indexOf(":");
+                    if (at != -1) {
+                        hostname = content.substring(0, at);
+                        try {
+                            final String portText = content.substring(at + 1);
+                            port = !TextUtils.isEmpty(portText) ? Integer.parseInt(portText) : -1;
+                        } catch (final NumberFormatException ex) {
+                            return null;
                         }
+                    } else {
+                        hostname = content;
+                        port = -1;
+                    }
+                    try {
+                        return new HttpHost(hostname, port, scheme);
+                    } catch (final IllegalArgumentException ex) {
+                        return null;
                     }
                 }
-            }
-            final String scheme = uri.getScheme();
-            if (!TextUtils.isBlank(host)) {
-                try {
-                    target = new HttpHost(host, port, scheme);
-                } catch (final IllegalArgumentException ignore) {
-                }
+            } else {
+                return new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
             }
         }
-        return target;
+        return null;
     }
 
     /**
diff --git a/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java b/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java
index 1899666..98a44bc 100644
--- a/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java
+++ b/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java
@@ -273,14 +273,16 @@ public class TestURIUtils {
 
         Assert.assertEquals(new HttpHost("localhost",8080),
                 URIUtils.extractHost(new URI("http://localhost:8080/;sessionid=stuff/abcd")));
-        Assert.assertEquals(new HttpHost("localhost",8080),
+        Assert.assertEquals(null,
                 URIUtils.extractHost(new URI("http://localhost:8080;sessionid=stuff/abcd")));
-        Assert.assertEquals(new HttpHost("localhost",-1),
+        Assert.assertEquals(null,
                 URIUtils.extractHost(new URI("http://localhost:;sessionid=stuff/abcd")));
         Assert.assertEquals(null,
                 URIUtils.extractHost(new URI("http://:80/robots.txt")));
         Assert.assertEquals(null,
                 URIUtils.extractHost(new URI("http://some%20domain:80/robots.txt")));
+        Assert.assertEquals(null,
+                URIUtils.extractHost(new URI("http://blah@goggle.com:80@google.com/")));
     }
 
     @Test


[httpcomponents-client] 03/03: Updated release notes for HttpClient 4.5.13 release

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

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

commit 60f8edb242aa3f868098512cd9559b8846a3d44c
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Jul 8 08:10:46 2020 -0400

    Updated release notes for HttpClient 4.5.13 release
---
 RELEASE_NOTES.txt | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index fefa322..d02731a 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -1,8 +1,31 @@
+Release 4.5.13
+-------------------
+
+This is a maintenance release that fixes incorrect handling of malformed authority component
+in request URIs.
+
+
+Changelog:
+-------------------
+
+* Incorrect handling of malformed authority component by URIUtils#extractHost.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
+* Avoid updating Content-Length header in a 304 response.
+  Contributed by Dirk Henselin <dirk.henselin at vwgis.de>
+
+* Bug fix: BasicExpiresHandler is annotated as immutable but is not (#239)
+  Contributed by Gary Gregory <ggregory at apache.org>
+ 
+* HTTPCLIENT-2076: Fixed NPE in LaxExpiresHandler (#222).
+  Contributed by heejeongkim <aprilhjk at gmail.com>
+
+
 Release 4.5.12
 -------------------
 
 This is a maintenance release that fixes a regression introduced by the previous release
-that caused rejection of ceritificates with non-standard domains.
+that caused rejection of certificates with non-standard domains.
 
 Changelog:
 -------------------
@@ -21,7 +44,6 @@ Changelog:
   Contributed by Oleg Kalnichevski <olegk at apache.org>
 
 
-
 Release 4.5.11
 -------------------