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/09/19 10:18:34 UTC

[httpcomponents-client] branch 5.1.x updated (e7f155d -> 8b88d2a)

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

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


    from e7f155d  HTTPCLIENT-2078: Log debug message when no credentials for given auth scope are found
     new 32d8e68  Avoid updating Content-Length header in a 304 response.
     new 36d5e2d  Upgraded HttpCore dependency to version 5.1-beta1
     new cb88274  Replaced deprecated TokenParser
     new 8b88d2a  Replaced deprecated URLEncodedUtils

The 4 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:
 .../http/impl/cache/CacheUpdateHandler.java        |  6 ++++--
 .../http/impl/cache/TestCacheUpdateHandler.java    | 20 +++++++++++++++++
 .../org/apache/hc/client5/http/fluent/Request.java |  4 ++--
 .../client5/http/entity/UrlEncodedFormEntity.java  |  4 ++--
 .../http/impl/auth/AuthChallengeParser.java        | 10 ++++-----
 .../http/impl/cookie/LaxExpiresHandler.java        |  8 +++----
 .../http/impl/cookie/RFC6265CookieSpec.java        | 19 ++++++++--------
 .../client5/http/ssl/DistinguishedNameParser.java  | 25 +++++++++++-----------
 .../apache/hc/client5/http/utils/TestURIUtils.java | 22 +++++++++----------
 pom.xml                                            |  2 +-
 10 files changed, 70 insertions(+), 50 deletions(-)


[httpcomponents-client] 02/04: Upgraded HttpCore dependency to version 5.1-beta1

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

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

commit 36d5e2dbd31c3b29fd16432bf20458b8a0ad7f46
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Wed Sep 16 16:58:52 2020 +0200

    Upgraded HttpCore dependency to version 5.1-beta1
---
 .../apache/hc/client5/http/utils/TestURIUtils.java | 22 +++++++++++-----------
 pom.xml                                            |  2 +-
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestURIUtils.java b/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestURIUtils.java
index e2d0340..3706d55 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestURIUtils.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestURIUtils.java
@@ -73,7 +73,7 @@ public class TestURIUtils {
                 URI.create("http://thathost")).toString());
         Assert.assertEquals("http://thathost/", URIUtils.rewriteURI(
                 URI.create("http://ThatHost")).toString());
-        Assert.assertEquals("http://That_Host/", URIUtils.rewriteURI(
+        Assert.assertEquals("http://that_host/", URIUtils.rewriteURI(
                 URI.create("http://That_Host")).toString());
         Assert.assertEquals("http://thishost/Fragment_identifier%23Examples",
                 URIUtils.rewriteURI(
@@ -111,8 +111,8 @@ public class TestURIUtils {
         Assert.assertEquals("http://www.example.com/a/", URIUtils.resolve(this.baseURI, "http://www.example.com/a%2f").toString());
         Assert.assertEquals("http://www.example.com/?q=%26", URIUtils.resolve(this.baseURI, "http://www.example.com/?q=%26").toString());
         Assert.assertEquals("http://www.example.com/%23?q=%26", URIUtils.resolve(this.baseURI, "http://www.example.com/%23?q=%26").toString());
-        Assert.assertEquals("http://www.example.com/blah-(%20-blah-%20&%20-blah-%20)-blah/",
-                URIUtils.resolve(this.baseURI, "http://www.example.com/blah-%28%20-blah-%20%26%20-blah-%20%29-blah/").toString());
+        Assert.assertEquals("http://www.example.com/blah-%28%20-blah-%20%26%20-blah-%20%29-blah/",
+                URIUtils.resolve(this.baseURI, "http://www.example.com/blah-%28%20-blah-%20&%20-blah-%20)-blah/").toString());
     }
 
     @Test
@@ -122,21 +122,21 @@ public class TestURIUtils {
         Assert.assertEquals("http://a/b/c/g", URIUtils.resolve(this.baseURI, "./g").toString());
         Assert.assertEquals("http://a/b/c/g/", URIUtils.resolve(this.baseURI, "g/").toString());
         Assert.assertEquals("http://a/g", URIUtils.resolve(this.baseURI, "/g").toString());
-        Assert.assertEquals("http://g", URIUtils.resolve(this.baseURI, "//g").toString());
+        Assert.assertEquals("http://g/", URIUtils.resolve(this.baseURI, "//g").toString());
         Assert.assertEquals("http://a/b/c/d;p?y", URIUtils.resolve(this.baseURI, "?y").toString());
         Assert.assertEquals("http://a/b/c/d;p?y#f", URIUtils.resolve(this.baseURI, "?y#f")
                 .toString());
         Assert.assertEquals("http://a/b/c/g?y", URIUtils.resolve(this.baseURI, "g?y").toString());
-        Assert.assertEquals("http://a/b/c/d;p?q#s", URIUtils.resolve(this.baseURI, "#s")
+        Assert.assertEquals("http://a/b/c/d%3Bp?q#s", URIUtils.resolve(this.baseURI, "#s")
                 .toString());
         Assert.assertEquals("http://a/b/c/g#s", URIUtils.resolve(this.baseURI, "g#s").toString());
         Assert.assertEquals("http://a/b/c/g?y#s", URIUtils.resolve(this.baseURI, "g?y#s")
                 .toString());
-        Assert.assertEquals("http://a/b/c/;x", URIUtils.resolve(this.baseURI, ";x").toString());
-        Assert.assertEquals("http://a/b/c/g;x", URIUtils.resolve(this.baseURI, "g;x").toString());
-        Assert.assertEquals("http://a/b/c/g;x?y#s", URIUtils.resolve(this.baseURI, "g;x?y#s")
+        Assert.assertEquals("http://a/b/c/%3Bx", URIUtils.resolve(this.baseURI, ";x").toString());
+        Assert.assertEquals("http://a/b/c/g%3Bx", URIUtils.resolve(this.baseURI, "g;x").toString());
+        Assert.assertEquals("http://a/b/c/g%3Bx?y#s", URIUtils.resolve(this.baseURI, "g;x?y#s")
                 .toString());
-        Assert.assertEquals("http://a/b/c/d;p?q", URIUtils.resolve(this.baseURI, "").toString());
+        Assert.assertEquals("http://a/b/c/d%3Bp?q", URIUtils.resolve(this.baseURI, "").toString());
         Assert.assertEquals("http://a/b/c/", URIUtils.resolve(this.baseURI, ".").toString());
         Assert.assertEquals("http://a/b/c/", URIUtils.resolve(this.baseURI, "./").toString());
         Assert.assertEquals("http://a/b/", URIUtils.resolve(this.baseURI, "..").toString());
@@ -158,7 +158,7 @@ public class TestURIUtils {
         Assert.assertEquals("http://a/b/c/g/", URIUtils.resolve(this.baseURI, "./g/.").toString());
         Assert.assertEquals("http://a/b/c/g/h", URIUtils.resolve(this.baseURI, "g/./h").toString());
         Assert.assertEquals("http://a/b/c/h", URIUtils.resolve(this.baseURI, "g/../h").toString());
-        Assert.assertEquals("http://a/b/c/g;x=1/y", URIUtils.resolve(this.baseURI, "g;x=1/./y")
+        Assert.assertEquals("http://a/b/c/g%3Bx%3D1/y", URIUtils.resolve(this.baseURI, "g;x=1/./y")
                 .toString());
         Assert.assertEquals("http://a/b/c/y", URIUtils.resolve(this.baseURI, "g;x=1/../y")
                 .toString());
@@ -183,7 +183,7 @@ public class TestURIUtils {
         Assert.assertEquals("example://a/b/c/%7Bfoo%7D", URIUtils.resolve(this.baseURI, "eXAMPLE://a/./b/../b/%63/%7bfoo%7d").toString());
         Assert.assertEquals("file://localhost/etc/fstab", URIUtils.resolve(this.baseURI, "file://localhost/etc/fstab").toString());
         Assert.assertEquals("file:///etc/fstab", URIUtils.resolve(this.baseURI, "file:///etc/fstab").toString());
-        Assert.assertEquals("file://localhost/c:/WINDOWS/clock.avi", URIUtils.resolve(this.baseURI, "file://localhost/c:/WINDOWS/clock.avi").toString());
+        Assert.assertEquals("file://localhost/c%3A/WINDOWS/clock.avi", URIUtils.resolve(this.baseURI, "file://localhost/c:/WINDOWS/clock.avi").toString());
         Assert.assertEquals("file:///c:/WINDOWS/clock.avi", URIUtils.resolve(this.baseURI, "file:///c:/WINDOWS/clock.avi").toString());
         Assert.assertEquals("file://hostname/path/to/the%20file.txt", URIUtils.resolve(this.baseURI, "file://hostname/path/to/the%20file.txt").toString());
         Assert.assertEquals("file:///c:/path/to/the%20file.txt", URIUtils.resolve(this.baseURI, "file:///c:/path/to/the%20file.txt").toString());
diff --git a/pom.xml b/pom.xml
index a951b9d..b41451a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -67,7 +67,7 @@
   <properties>
     <maven.compiler.source>1.7</maven.compiler.source>
     <maven.compiler.target>1.7</maven.compiler.target>
-    <httpcore.version>5.0.1</httpcore.version>
+    <httpcore.version>5.1-beta1</httpcore.version>
     <log4j.version>2.9.1</log4j.version>
     <commons-codec.version>1.13</commons-codec.version>
     <conscrypt.version>2.2.1</conscrypt.version>


[httpcomponents-client] 03/04: Replaced deprecated TokenParser

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

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

commit cb88274e1abdf0756f857cbf829cac902ab0bf51
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Wed Sep 16 17:14:11 2020 +0200

    Replaced deprecated TokenParser
---
 .../http/impl/auth/AuthChallengeParser.java        | 10 ++++-----
 .../http/impl/cookie/LaxExpiresHandler.java        |  8 +++----
 .../http/impl/cookie/RFC6265CookieSpec.java        | 19 ++++++++--------
 .../client5/http/ssl/DistinguishedNameParser.java  | 25 +++++++++++-----------
 4 files changed, 30 insertions(+), 32 deletions(-)

diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/AuthChallengeParser.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/AuthChallengeParser.java
index 8fd57fe..3a7d1a7 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/AuthChallengeParser.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/AuthChallengeParser.java
@@ -37,8 +37,8 @@ import org.apache.hc.core5.http.NameValuePair;
 import org.apache.hc.core5.http.ParseException;
 import org.apache.hc.core5.http.message.BasicNameValuePair;
 import org.apache.hc.core5.http.message.ParserCursor;
-import org.apache.hc.core5.http.message.TokenParser;
 import org.apache.hc.core5.util.TextUtils;
+import org.apache.hc.core5.util.Tokenizer;
 
 /**
  * Authentication challenge parser.
@@ -49,7 +49,7 @@ public class AuthChallengeParser {
 
     public static final AuthChallengeParser INSTANCE = new AuthChallengeParser();
 
-    private final TokenParser tokenParser = TokenParser.INSTANCE;
+    private final Tokenizer tokenParser = Tokenizer.INSTANCE;
 
     private final static char BLANK            = ' ';
     private final static char COMMA_CHAR       = ',';
@@ -57,9 +57,9 @@ public class AuthChallengeParser {
 
     // IMPORTANT!
     // These private static variables must be treated as immutable and never exposed outside this class
-    private static final BitSet TERMINATORS = TokenParser.INIT_BITSET(BLANK, EQUAL_CHAR, COMMA_CHAR);
-    private static final BitSet DELIMITER = TokenParser.INIT_BITSET(COMMA_CHAR);
-    private static final BitSet SPACE = TokenParser.INIT_BITSET(BLANK);
+    private static final BitSet TERMINATORS = Tokenizer.INIT_BITSET(BLANK, EQUAL_CHAR, COMMA_CHAR);
+    private static final BitSet DELIMITER = Tokenizer.INIT_BITSET(COMMA_CHAR);
+    private static final BitSet SPACE = Tokenizer.INIT_BITSET(BLANK);
 
     static class ChallengeInt {
 
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxExpiresHandler.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxExpiresHandler.java
index c48be4f..357f8a8 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxExpiresHandler.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxExpiresHandler.java
@@ -41,9 +41,9 @@ import org.apache.hc.client5.http.cookie.MalformedCookieException;
 import org.apache.hc.client5.http.cookie.SetCookie;
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
-import org.apache.hc.core5.http.message.ParserCursor;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.TextUtils;
+import org.apache.hc.core5.util.Tokenizer;
 
 /**
  * Cookie {@code expires} attribute handler conformant to the more relaxed interpretation
@@ -111,7 +111,7 @@ public class LaxExpiresHandler extends AbstractCookieAttributeHandler implements
         if (TextUtils.isBlank(value)) {
             return;
         }
-        final ParserCursor cursor = new ParserCursor(0, value.length());
+        final Tokenizer.Cursor cursor = new Tokenizer.Cursor(0, value.length());
         final StringBuilder content = new StringBuilder();
 
         int second = 0, minute = 0, hour = 0, day = 0, month = 0, year = 0;
@@ -188,7 +188,7 @@ public class LaxExpiresHandler extends AbstractCookieAttributeHandler implements
         cookie.setExpiryDate(c.getTime());
     }
 
-    private void skipDelims(final CharSequence buf, final ParserCursor cursor) {
+    private void skipDelims(final CharSequence buf, final Tokenizer.Cursor cursor) {
         int pos = cursor.getPos();
         final int indexFrom = cursor.getPos();
         final int indexTo = cursor.getUpperBound();
@@ -203,7 +203,7 @@ public class LaxExpiresHandler extends AbstractCookieAttributeHandler implements
         cursor.updatePos(pos);
     }
 
-    private void copyContent(final CharSequence buf, final ParserCursor cursor, final StringBuilder dst) {
+    private void copyContent(final CharSequence buf, final Tokenizer.Cursor cursor, final StringBuilder dst) {
         int pos = cursor.getPos();
         final int indexFrom = cursor.getPos();
         final int indexTo = cursor.getUpperBound();
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265CookieSpec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265CookieSpec.java
index 97668f0..c815bc0 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265CookieSpec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265CookieSpec.java
@@ -50,10 +50,9 @@ import org.apache.hc.core5.http.FormattedHeader;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.ParseException;
 import org.apache.hc.core5.http.message.BufferedHeader;
-import org.apache.hc.core5.http.message.ParserCursor;
-import org.apache.hc.core5.http.message.TokenParser;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.CharArrayBuffer;
+import org.apache.hc.core5.util.Tokenizer;
 
 /**
  * Cookie management functions shared by RFC C6265 compliant specification.
@@ -71,14 +70,14 @@ public class RFC6265CookieSpec implements CookieSpec {
 
     // IMPORTANT!
     // These private static variables must be treated as immutable and never exposed outside this class
-    private static final BitSet TOKEN_DELIMS = TokenParser.INIT_BITSET(EQUAL_CHAR, PARAM_DELIMITER);
-    private static final BitSet VALUE_DELIMS = TokenParser.INIT_BITSET(PARAM_DELIMITER);
-    private static final BitSet SPECIAL_CHARS = TokenParser.INIT_BITSET(' ',
+    private static final BitSet TOKEN_DELIMS = Tokenizer.INIT_BITSET(EQUAL_CHAR, PARAM_DELIMITER);
+    private static final BitSet VALUE_DELIMS = Tokenizer.INIT_BITSET(PARAM_DELIMITER);
+    private static final BitSet SPECIAL_CHARS = Tokenizer.INIT_BITSET(' ',
             DQUOTE_CHAR, COMMA_CHAR, PARAM_DELIMITER, ESCAPE_CHAR);
 
     private final CookieAttributeHandler[] attribHandlers;
     private final Map<String, CookieAttributeHandler> attribHandlerMap;
-    private final TokenParser tokenParser;
+    private final Tokenizer tokenParser;
 
     protected RFC6265CookieSpec(final CommonCookieAttributeHandler... handlers) {
         super();
@@ -87,7 +86,7 @@ public class RFC6265CookieSpec implements CookieSpec {
         for (final CommonCookieAttributeHandler handler: handlers) {
             this.attribHandlerMap.put(handler.getAttributeName().toLowerCase(Locale.ROOT), handler);
         }
-        this.tokenParser = TokenParser.INSTANCE;
+        this.tokenParser = Tokenizer.INSTANCE;
     }
 
     static String getDefaultPath(final CookieOrigin origin) {
@@ -115,10 +114,10 @@ public class RFC6265CookieSpec implements CookieSpec {
             throw new MalformedCookieException("Unrecognized cookie header: '" + header + "'");
         }
         final CharArrayBuffer buffer;
-        final ParserCursor cursor;
+        final Tokenizer.Cursor cursor;
         if (header instanceof FormattedHeader) {
             buffer = ((FormattedHeader) header).getBuffer();
-            cursor = new ParserCursor(((FormattedHeader) header).getValuePos(), buffer.length());
+            cursor = new Tokenizer.Cursor(((FormattedHeader) header).getValuePos(), buffer.length());
         } else {
             final String s = header.getValue();
             if (s == null) {
@@ -126,7 +125,7 @@ public class RFC6265CookieSpec implements CookieSpec {
             }
             buffer = new CharArrayBuffer(s.length());
             buffer.append(s);
-            cursor = new ParserCursor(0, buffer.length());
+            cursor = new Tokenizer.Cursor(0, buffer.length());
         }
         final String name = tokenParser.parseToken(buffer, cursor, TOKEN_DELIMS);
         if (name.isEmpty()) {
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DistinguishedNameParser.java b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DistinguishedNameParser.java
index 0053c1c..4e3dc8a 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DistinguishedNameParser.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DistinguishedNameParser.java
@@ -33,32 +33,31 @@ import java.util.List;
 
 import org.apache.hc.core5.http.NameValuePair;
 import org.apache.hc.core5.http.message.BasicNameValuePair;
-import org.apache.hc.core5.http.message.ParserCursor;
-import org.apache.hc.core5.http.message.TokenParser;
 import org.apache.hc.core5.util.CharArrayBuffer;
+import org.apache.hc.core5.util.Tokenizer;
 
 final class DistinguishedNameParser {
 
     public final static DistinguishedNameParser INSTANCE = new DistinguishedNameParser();
 
-    private static final BitSet EQUAL_OR_COMMA_OR_PLUS      = TokenParser.INIT_BITSET('=', ',', '+');
-    private static final BitSet COMMA_OR_PLUS               = TokenParser.INIT_BITSET(',', '+');
+    private static final BitSet EQUAL_OR_COMMA_OR_PLUS      = Tokenizer.INIT_BITSET('=', ',', '+');
+    private static final BitSet COMMA_OR_PLUS               = Tokenizer.INIT_BITSET(',', '+');
 
-    private final TokenParser tokenParser;
+    private final Tokenizer tokenParser;
 
     DistinguishedNameParser() {
         this.tokenParser = new InternalTokenParser();
     }
 
-    private String parseToken(final CharArrayBuffer buf, final ParserCursor cursor, final BitSet delimiters) {
+    private String parseToken(final CharArrayBuffer buf, final Tokenizer.Cursor cursor, final BitSet delimiters) {
         return tokenParser.parseToken(buf, cursor, delimiters);
     }
 
-    private String parseValue(final CharArrayBuffer buf, final ParserCursor cursor, final BitSet delimiters) {
+    private String parseValue(final CharArrayBuffer buf, final Tokenizer.Cursor cursor, final BitSet delimiters) {
         return tokenParser.parseValue(buf, cursor, delimiters);
     }
 
-    private NameValuePair parseParameter(final CharArrayBuffer buf, final ParserCursor cursor) {
+    private NameValuePair parseParameter(final CharArrayBuffer buf, final Tokenizer.Cursor cursor) {
         final String name = parseToken(buf, cursor, EQUAL_OR_COMMA_OR_PLUS);
         if (cursor.atEnd()) {
             return new BasicNameValuePair(name, null);
@@ -75,7 +74,7 @@ final class DistinguishedNameParser {
         return new BasicNameValuePair(name, value);
     }
 
-    List<NameValuePair> parse(final CharArrayBuffer buf, final ParserCursor cursor) {
+    List<NameValuePair> parse(final CharArrayBuffer buf, final Tokenizer.Cursor cursor) {
         final List<NameValuePair> params = new ArrayList<>();
         tokenParser.skipWhiteSpace(buf, cursor);
         while (!cursor.atEnd()) {
@@ -91,16 +90,16 @@ final class DistinguishedNameParser {
         }
         final CharArrayBuffer buffer = new CharArrayBuffer(s.length());
         buffer.append(s);
-        final ParserCursor cursor = new ParserCursor(0, s.length());
+        final Tokenizer.Cursor cursor = new Tokenizer.Cursor(0, s.length());
         return parse(buffer, cursor);
     }
 
-    static class InternalTokenParser extends TokenParser {
+    static class InternalTokenParser extends Tokenizer {
 
         @Override
         public void copyUnquotedContent(
                 final CharSequence buf,
-                final ParserCursor cursor,
+                final Tokenizer.Cursor cursor,
                 final BitSet delimiters,
                 final StringBuilder dst) {
             int pos = cursor.getPos();
@@ -114,7 +113,7 @@ final class DistinguishedNameParser {
                     escaped = false;
                 } else {
                     if ((delimiters != null && delimiters.get(current))
-                            || TokenParser.isWhitespace(current) || current == '\"') {
+                            || Tokenizer.isWhitespace(current) || current == '\"') {
                         break;
                     } else if (current == '\\') {
                         escaped = true;


[httpcomponents-client] 04/04: Replaced deprecated URLEncodedUtils

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

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

commit 8b88d2a34bd01ab49b1eaa73e517a9e54cbf1d2b
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Wed Sep 16 17:17:44 2020 +0200

    Replaced deprecated URLEncodedUtils
---
 .../src/main/java/org/apache/hc/client5/http/fluent/Request.java      | 4 ++--
 .../java/org/apache/hc/client5/http/entity/UrlEncodedFormEntity.java  | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java b/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java
index b24927d..492adb7 100644
--- a/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java
+++ b/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java
@@ -60,7 +60,7 @@ import org.apache.hc.core5.http.NameValuePair;
 import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
 import org.apache.hc.core5.http.io.entity.FileEntity;
 import org.apache.hc.core5.http.io.entity.InputStreamEntity;
-import org.apache.hc.core5.net.URLEncodedUtils;
+import org.apache.hc.core5.net.WWWFormCodec;
 import org.apache.hc.core5.util.Timeout;
 
 /**
@@ -334,7 +334,7 @@ public class Request {
         }
         final ContentType contentType = charset != null ?
                 ContentType.APPLICATION_FORM_URLENCODED.withCharset(charset) : ContentType.APPLICATION_FORM_URLENCODED;
-        final String s = URLEncodedUtils.format(paramList, contentType.getCharset());
+        final String s = WWWFormCodec.format(paramList, contentType.getCharset());
         return bodyString(s, contentType);
     }
 
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/UrlEncodedFormEntity.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/UrlEncodedFormEntity.java
index 9e18a77..156663a 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/UrlEncodedFormEntity.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/UrlEncodedFormEntity.java
@@ -32,7 +32,7 @@ import java.util.List;
 import org.apache.hc.core5.http.ContentType;
 import org.apache.hc.core5.http.NameValuePair;
 import org.apache.hc.core5.http.io.entity.StringEntity;
-import org.apache.hc.core5.net.URLEncodedUtils;
+import org.apache.hc.core5.net.WWWFormCodec;
 
 /**
  * An entity composed of a list of url-encoded pairs.
@@ -54,7 +54,7 @@ public class UrlEncodedFormEntity extends StringEntity {
     public UrlEncodedFormEntity(
             final Iterable<? extends NameValuePair> parameters,
             final Charset charset) {
-        super(URLEncodedUtils.format(
+        super(WWWFormCodec.format(
                 parameters,
                 charset != null ? charset : ContentType.APPLICATION_FORM_URLENCODED.getCharset()),
                 charset != null ? ContentType.APPLICATION_FORM_URLENCODED.withCharset(charset) : ContentType.APPLICATION_FORM_URLENCODED);


[httpcomponents-client] 01/04: 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 5.1.x
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git

commit 32d8e68b8da00fbd74026e73f0c758daabda55ae
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.
---
 .../client5/http/impl/cache/CacheUpdateHandler.java  |  6 ++++--
 .../http/impl/cache/TestCacheUpdateHandler.java      | 20 ++++++++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheUpdateHandler.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheUpdateHandler.java
index d0ea32c..2302148 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheUpdateHandler.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheUpdateHandler.java
@@ -141,7 +141,8 @@ class CacheUpdateHandler {
         for (final Iterator<Header> it = response.headerIterator(); it.hasNext(); ) {
             final Header responseHeader = it.next();
             // Since we do not expect a content in a 304 response, should retain the original Content-Encoding header
-            if (HttpHeaders.CONTENT_ENCODING.equals(responseHeader.getName())) {
+            if (HttpHeaders.CONTENT_ENCODING.equals(responseHeader.getName())
+                    || HttpHeaders.CONTENT_LENGTH.equals(responseHeader.getName())) {
                 continue;
             }
             headerGroup.removeHeaders(responseHeader.getName());
@@ -159,7 +160,8 @@ class CacheUpdateHandler {
         for (final Iterator<Header> it = response.headerIterator(); it.hasNext(); ) {
             final Header responseHeader = it.next();
             // Since we do not expect a content in a 304 response, should update the cache entry with Content-Encoding
-            if (HttpHeaders.CONTENT_ENCODING.equals(responseHeader.getName())) {
+            if (HttpHeaders.CONTENT_ENCODING.equals(responseHeader.getName())
+                    || HttpHeaders.CONTENT_LENGTH.equals(responseHeader.getName())) {
                 continue;
             }
             headerGroup.addHeader(responseHeader);
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheUpdateHandler.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheUpdateHandler.java
index 39816c0..26b441f 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheUpdateHandler.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCacheUpdateHandler.java
@@ -266,6 +266,26 @@ public class TestCacheUpdateHandler {
         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 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.getHeaders();
+        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)) {