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 2016/11/19 09:34:28 UTC

svn commit: r1770475 - in /httpcomponents/httpcore/trunk: httpcore5-ab/src/main/java/org/apache/hc/core5/http/benchmark/ httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/ httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/ httpcore5-tes...

Author: olegk
Date: Sat Nov 19 09:34:27 2016
New Revision: 1770475

URL: http://svn.apache.org/viewvc?rev=1770475&view=rev
Log:
Improved representation of HTTP request authority; added message support methods

Added:
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/net/URIAuthority.java   (contents, props changed)
      - copied, changed from r1769911, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/net/URIHost.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIAuthority.java   (contents, props changed)
      - copied, changed from r1769911, httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIHost.java
Removed:
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/net/URIHost.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIHost.java
Modified:
    httpcomponents/httpcore/trunk/httpcore5-ab/src/main/java/org/apache/hc/core5/http/benchmark/HttpBenchmark.java
    httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/DefaultH2RequestConverter.java
    httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/TestDefaultH2RequestConverter.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestClient.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestClient.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/Http1IntegrationTest.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/HttpRequest.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/bootstrap/AsyncServerExchangeHandlerRegistry.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicHttpRequest.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/message/HttpRequestWrapper.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/message/MessageSupport.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestTargetHost.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestValidateHost.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/TestHttpHost.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/message/TestBasicMessages.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/protocol/TestStandardInterceptors.java

Modified: httpcomponents/httpcore/trunk/httpcore5-ab/src/main/java/org/apache/hc/core5/http/benchmark/HttpBenchmark.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-ab/src/main/java/org/apache/hc/core5/http/benchmark/HttpBenchmark.java?rev=1770475&r1=1770474&r2=1770475&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-ab/src/main/java/org/apache/hc/core5/http/benchmark/HttpBenchmark.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-ab/src/main/java/org/apache/hc/core5/http/benchmark/HttpBenchmark.java Sat Nov 19 09:34:27 2016
@@ -53,6 +53,7 @@ import org.apache.hc.core5.http.ContentT
 import org.apache.hc.core5.http.io.entity.FileEntity;
 import org.apache.hc.core5.http.io.entity.StringEntity;
 import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
+import org.apache.hc.core5.net.URIAuthority;
 import org.apache.hc.core5.ssl.SSLContextBuilder;
 import org.apache.hc.core5.ssl.TrustStrategy;
 
@@ -153,7 +154,7 @@ public class HttpBenchmark {
             request.addHeader(new DefaultHeader("SOAPAction", config.getSoapAction()));
         }
         request.setScheme(host.getSchemeName());
-        request.setAuthority(host.toHostString());
+        request.setAuthority(new URIAuthority(host));
         return request;
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/DefaultH2RequestConverter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/DefaultH2RequestConverter.java?rev=1770475&r1=1770474&r2=1770475&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/DefaultH2RequestConverter.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/DefaultH2RequestConverter.java Sat Nov 19 09:34:27 2016
@@ -27,6 +27,7 @@
 
 package org.apache.hc.core5.http2.impl;
 
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -42,6 +43,7 @@ import org.apache.hc.core5.http.message.
 import org.apache.hc.core5.http.message.BasicHttpRequest;
 import org.apache.hc.core5.http2.H2MessageConverter;
 import org.apache.hc.core5.http2.H2PseudoRequestHeaders;
+import org.apache.hc.core5.net.URIAuthority;
 import org.apache.hc.core5.util.TextUtils;
 
 /**
@@ -130,7 +132,11 @@ public final class DefaultH2RequestConve
         final HttpRequest httpRequest = new BasicHttpRequest(method, path);
         httpRequest.setVersion(HttpVersion.HTTP_2);
         httpRequest.setScheme(scheme);
-        httpRequest.setAuthority(authority);
+        try {
+            httpRequest.setAuthority(URIAuthority.create(authority));
+        } catch (URISyntaxException ex) {
+            throw new ProtocolException(ex.getMessage(), ex);
+        }
         httpRequest.setPath(path);
         for (int i = 0; i < messageHeaders.size(); i++) {
             httpRequest.addHeader(messageHeaders.get(i));
@@ -145,7 +151,7 @@ public final class DefaultH2RequestConve
         }
         final boolean optionMethod = "CONNECT".equalsIgnoreCase(message.getMethod());
         if (optionMethod) {
-            if (TextUtils.isBlank(message.getAuthority())) {
+            if (message.getAuthority() == null) {
                 throw new ProtocolException("CONNECT request authority is not set");
             }
             if (message.getPath() != null) {

Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/TestDefaultH2RequestConverter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/TestDefaultH2RequestConverter.java?rev=1770475&r1=1770474&r2=1770475&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/TestDefaultH2RequestConverter.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/TestDefaultH2RequestConverter.java Sat Nov 19 09:34:27 2016
@@ -36,6 +36,7 @@ import org.apache.hc.core5.http.HttpHost
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.message.BasicHeader;
 import org.apache.hc.core5.http.message.BasicHttpRequest;
+import org.apache.hc.core5.net.URIAuthority;
 import org.junit.Assert;
 import org.junit.Rule;
 import org.junit.Test;
@@ -61,7 +62,7 @@ public class TestDefaultH2RequestConvert
         Assert.assertNotNull(request);
         Assert.assertEquals("GET", request.getMethod());
         Assert.assertEquals("http", request.getScheme());
-        Assert.assertEquals("www.example.com", request.getAuthority());
+        Assert.assertEquals(new URIAuthority("www.example.com"), request.getAuthority());
         Assert.assertEquals("/", request.getPath());
         final Header[] allHeaders = request.getAllHeaders();
         Assert.assertEquals(1, allHeaders.length);
@@ -395,7 +396,7 @@ public class TestDefaultH2RequestConvert
         thrown.expectMessage("CONNECT request path must be null");
 
         final HttpRequest request = new BasicHttpRequest("CONNECT", "/");
-        request.setAuthority("host");
+        request.setAuthority(new URIAuthority("host"));
         request.addHeader("Custom123", "Value");
 
         final DefaultH2RequestConverter converter = new DefaultH2RequestConverter();

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestClient.java?rev=1770475&r1=1770474&r2=1770475&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestClient.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestClient.java Sat Nov 19 09:34:27 2016
@@ -40,6 +40,7 @@ import org.apache.hc.core5.http.impl.io.
 import org.apache.hc.core5.http.impl.io.bootstrap.RequesterBootstrap;
 import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
+import org.apache.hc.core5.net.URIAuthority;
 import org.apache.hc.core5.util.Asserts;
 import org.apache.hc.core5.util.LangUtils;
 
@@ -100,9 +101,9 @@ public class ClassicTestClient {
             this.connection.setSocketTimeout(this.timeout);
         }
         if (request.getAuthority() == null) {
-            request.setAuthority(targetHost.toHostString());
-            request.setScheme(targetHost.getSchemeName());
+            request.setAuthority(new URIAuthority(targetHost));
         }
+        request.setScheme(targetHost.getSchemeName());
         return this.requester.execute(this.connection, request, context);
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestClient.java?rev=1770475&r1=1770474&r2=1770475&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestClient.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestClient.java Sat Nov 19 09:34:27 2016
@@ -42,13 +42,12 @@ import org.apache.hc.core5.http.HttpExce
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.MisdirectedRequestException;
-import org.apache.hc.core5.http.ProtocolException;
+import org.apache.hc.core5.http.Supplier;
 import org.apache.hc.core5.http.impl.nio.bootstrap.AsyncRequester;
 import org.apache.hc.core5.http.impl.nio.bootstrap.ClientEndpoint;
 import org.apache.hc.core5.http.impl.nio.bootstrap.ClientEndpointImpl;
 import org.apache.hc.core5.http.nio.AsyncPushConsumer;
 import org.apache.hc.core5.http.nio.HandlerFactory;
-import org.apache.hc.core5.http.Supplier;
 import org.apache.hc.core5.http.nio.command.ShutdownCommand;
 import org.apache.hc.core5.http.nio.command.ShutdownType;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
@@ -56,6 +55,7 @@ import org.apache.hc.core5.http.protocol
 import org.apache.hc.core5.http2.bootstrap.Http2Processors;
 import org.apache.hc.core5.http2.config.H2Config;
 import org.apache.hc.core5.net.NamedEndpoint;
+import org.apache.hc.core5.net.URIAuthority;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
 import org.apache.hc.core5.reactor.IOReactorConfig;
 import org.apache.hc.core5.reactor.IOSession;
@@ -98,12 +98,7 @@ public class Http2TestClient extends Asy
 
     private AsyncPushConsumer createHandler(final HttpRequest request) throws HttpException {
 
-        final HttpHost authority;
-        try {
-            authority = request.getAuthority() != null ? HttpHost.create(request.getAuthority()) : null;
-        } catch (IllegalArgumentException ex) {
-            throw new ProtocolException("Invalid authority");
-        }
+        final URIAuthority authority = request.getAuthority();
         if (authority != null && !"localhost".equalsIgnoreCase(authority.getHostName())) {
             throw new MisdirectedRequestException("Not authoritative");
         }

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/Http1IntegrationTest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/Http1IntegrationTest.java?rev=1770475&r1=1770474&r2=1770475&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/Http1IntegrationTest.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/Http1IntegrationTest.java Sat Nov 19 09:34:27 2016
@@ -1255,7 +1255,7 @@ public class Http1IntegrationTest extend
                         new BasicAsyncEntityProducer("Hi there")),
                 new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
         final HttpRequest request2 = new BasicHttpRequest("POST", createRequestURI(serverEndpoint, "/hello-2"));
-        request2.addHeader(HttpHeaders.HOST, "");
+        request2.addHeader(HttpHeaders.HOST, "blah:blah");
         final Future<Message<HttpResponse, String>> future2 = streamEndpoint.execute(
                 new BasicRequestProducer(request2,
                         new BasicAsyncEntityProducer("Hi there")),

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java?rev=1770475&r1=1770474&r2=1770475&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java Sat Nov 19 09:34:27 2016
@@ -29,14 +29,16 @@ package org.apache.hc.core5.http;
 
 import java.io.Serializable;
 import java.net.InetAddress;
+import java.net.URISyntaxException;
 import java.util.Locale;
 
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.net.NamedEndpoint;
-import org.apache.hc.core5.net.URIHost;
+import org.apache.hc.core5.net.URIAuthority;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.LangUtils;
+import org.apache.hc.core5.util.TextUtils;
 
 /**
  * Holds all of the variables needed to describe an HTTP connection to a host.
@@ -67,6 +69,15 @@ public final class HttpHost implements N
 
     private final InetAddress address;
 
+    private HttpHost(final String hostname, final int port, final String scheme, final boolean internal) {
+        super();
+        this.hostname = hostname;
+        this.lcHostname = hostname;
+        this.schemeName = scheme;
+        this.port = port;
+        this.address = null;
+    }
+
     /**
      * Creates {@code HttpHost} instance with the given scheme, hostname and port.
      *
@@ -118,7 +129,7 @@ public final class HttpHost implements N
      *
      * @since 4.4
      */
-    public static HttpHost create(final String s) {
+    public static HttpHost create(final String s) throws URISyntaxException {
         if (s == null) {
             return null;
         }
@@ -127,6 +138,9 @@ public final class HttpHost implements N
         final int schemeIdx = text.indexOf("://");
         if (schemeIdx > 0) {
             scheme = text.substring(0, schemeIdx);
+            if (TextUtils.containsBlanks(scheme)) {
+                throw new URISyntaxException(s, "scheme contains blanks");
+            }
             text = text.substring(schemeIdx + 3);
         }
         int port = -1;
@@ -135,11 +149,17 @@ public final class HttpHost implements N
             try {
                 port = Integer.parseInt(text.substring(portIdx + 1));
             } catch (final NumberFormatException ex) {
-                throw new IllegalArgumentException("Invalid HTTP host: " + text);
+                throw new URISyntaxException(s, "invalid port");
             }
             text = text.substring(0, portIdx);
         }
-        return new HttpHost(text, port, scheme);
+        if (TextUtils.containsBlanks(text)) {
+            throw new URISyntaxException(s, "hostname contains blanks");
+        }
+        return new HttpHost(
+                text.toLowerCase(Locale.ROOT),
+                port,
+                scheme != null ? scheme.toLowerCase(Locale.ROOT) : DEFAULT_SCHEME_NAME, true);
     }
 
     /**
@@ -222,15 +242,15 @@ public final class HttpHost implements N
     /**
      * @since 5.0
      */
-    public HttpHost(final URIHost uriHost, final String scheme) {
-        this(Args.notNull(uriHost, "URI host").getHostName(), uriHost.getPort(), scheme);
+    public HttpHost(final NamedEndpoint namedEndpoint, final String scheme) {
+        this(namedEndpoint.getHostName(), namedEndpoint.getPort(), scheme);
     }
 
     /**
      * @since 5.0
      */
-    public HttpHost(final URIHost uriHost) {
-        this(uriHost, null);
+    public HttpHost(final URIAuthority authority) {
+        this(authority, null);
     }
 
     /**

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/HttpRequest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/HttpRequest.java?rev=1770475&r1=1770474&r2=1770475&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/HttpRequest.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/HttpRequest.java Sat Nov 19 09:34:27 2016
@@ -30,6 +30,8 @@ package org.apache.hc.core5.http;
 import java.net.URI;
 import java.net.URISyntaxException;
 
+import org.apache.hc.core5.net.URIAuthority;
+
 /**
  * A request message from a client to a server includes, within the
  * first line of that message, the method to be applied to the resource,
@@ -83,14 +85,14 @@ public interface HttpRequest extends Htt
      *
      * @since 5.0
      */
-    String getAuthority();
+    URIAuthority getAuthority();
 
     /**
      * Sets authority of this request message.
      *
      * @since 5.0
      */
-    void setAuthority(String authority);
+    void setAuthority(URIAuthority authority);
 
     /**
      * Returns request URI of this request message. It may be an absolute or relative URI.

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/bootstrap/AsyncServerExchangeHandlerRegistry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/bootstrap/AsyncServerExchangeHandlerRegistry.java?rev=1770475&r1=1770474&r2=1770475&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/bootstrap/AsyncServerExchangeHandlerRegistry.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/bootstrap/AsyncServerExchangeHandlerRegistry.java Sat Nov 19 09:34:27 2016
@@ -32,14 +32,14 @@ import java.util.concurrent.ConcurrentHa
 import java.util.concurrent.ConcurrentMap;
 
 import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpStatus;
+import org.apache.hc.core5.http.Supplier;
 import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
 import org.apache.hc.core5.http.nio.HandlerFactory;
-import org.apache.hc.core5.http.Supplier;
 import org.apache.hc.core5.http.nio.support.ImmediateResponseExchangeHandler;
 import org.apache.hc.core5.http.protocol.UriPatternMatcher;
+import org.apache.hc.core5.net.URIAuthority;
 import org.apache.hc.core5.util.Args;
 
 public class AsyncServerExchangeHandlerRegistry implements HandlerFactory<AsyncServerExchangeHandler> {
@@ -68,12 +68,7 @@ public class AsyncServerExchangeHandlerR
 
     @Override
     public AsyncServerExchangeHandler create(final HttpRequest request) throws HttpException {
-        final HttpHost authority;
-        try {
-            authority = request.getAuthority() != null ? HttpHost.create(request.getAuthority()) : null;
-        } catch (IllegalArgumentException ex) {
-            return new ImmediateResponseExchangeHandler(HttpStatus.SC_BAD_REQUEST, "Invalid authority");
-        }
+        final URIAuthority authority = request.getAuthority();
         final String key = authority != null ? authority.getHostName().toLowerCase(Locale.ROOT) : null;
         final UriPatternMatcher<Supplier<AsyncServerExchangeHandler>> patternMatcher = getPatternMatcher(key);
         if (patternMatcher == null) {

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicHttpRequest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicHttpRequest.java?rev=1770475&r1=1770474&r2=1770475&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicHttpRequest.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicHttpRequest.java Sat Nov 19 09:34:27 2016
@@ -33,6 +33,7 @@ import java.net.URISyntaxException;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.net.URIAuthority;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.TextUtils;
 
@@ -48,7 +49,7 @@ public class BasicHttpRequest extends He
     private final String method;
     private String path;
     private String scheme;
-    private String authority;
+    private URIAuthority authority;
     private ProtocolVersion version;
     private URI requestUri;
 
@@ -75,7 +76,7 @@ public class BasicHttpRequest extends He
         super();
         this.method = Args.notNull(method, "Method name");
         this.scheme = host != null ? host.getSchemeName() : null;
-        this.authority = host != null ? host.toHostString() : null;
+        this.authority = host != null ? new URIAuthority(host) : null;
         this.path = path;
     }
 
@@ -92,15 +93,18 @@ public class BasicHttpRequest extends He
         this.method = Args.notNull(method, "Method name");
         Args.notNull(requestUri, "Request URI");
         this.scheme = requestUri.getScheme();
-        this.authority = requestUri.getAuthority();
+        this.authority = requestUri.getHost() != null ? new URIAuthority(
+                requestUri.getRawUserInfo(),
+                requestUri.getHost(),
+                requestUri.getPort()) : null;
         final StringBuilder buf = new StringBuilder();
-        final String path = requestUri.getPath();
+        final String path = requestUri.getRawPath();
         if (!TextUtils.isBlank(path)) {
             buf.append(path);
         } else {
             buf.append("/");
         }
-        final String query = requestUri.getQuery();
+        final String query = requestUri.getRawQuery();
         if (query != null) {
             buf.append('?').append(query);
         }
@@ -157,12 +161,12 @@ public class BasicHttpRequest extends He
     }
 
     @Override
-    public String getAuthority() {
+    public URIAuthority getAuthority() {
         return this.authority;
     }
 
     @Override
-    public void setAuthority(final String authority) {
+    public void setAuthority(final URIAuthority authority) {
         this.authority = authority;
         this.requestUri = null;
     }
@@ -177,7 +181,11 @@ public class BasicHttpRequest extends He
         if (this.requestUri == null) {
             final StringBuilder buf = new StringBuilder();
             if (this.authority != null) {
-                buf.append(this.scheme != null ? this.scheme : "http").append("://").append(this.authority);
+                buf.append(this.scheme != null ? this.scheme : "http").append("://");
+                buf.append(this.authority.getHostName());
+                if (this.authority.getPort() >= 0) {
+                    buf.append(":").append(this.authority.getPort());
+                }
             }
             buf.append(this.path != null ? this.path : "/");
             this.requestUri = new URI(buf.toString());

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/message/HttpRequestWrapper.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/message/HttpRequestWrapper.java?rev=1770475&r1=1770474&r2=1770475&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/message/HttpRequestWrapper.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/message/HttpRequestWrapper.java Sat Nov 19 09:34:27 2016
@@ -31,6 +31,7 @@ import java.net.URI;
 import java.net.URISyntaxException;
 
 import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.net.URIAuthority;
 
 /**
  * {@link HttpRequest} wrapper.
@@ -70,12 +71,12 @@ public class HttpRequestWrapper extends
     }
 
     @Override
-    public String getAuthority() {
+    public URIAuthority getAuthority() {
         return message.getAuthority();
     }
 
     @Override
-    public void setAuthority(final String authority) {
+    public void setAuthority(final URIAuthority authority) {
         message.setAuthority(authority);
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/message/MessageSupport.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/message/MessageSupport.java?rev=1770475&r1=1770474&r2=1770475&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/message/MessageSupport.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/message/MessageSupport.java Sat Nov 19 09:34:27 2016
@@ -29,14 +29,17 @@ package org.apache.hc.core5.http.message
 
 import java.util.Arrays;
 import java.util.BitSet;
+import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.Set;
 
 import org.apache.hc.core5.http.EntityDetails;
 import org.apache.hc.core5.http.FormattedHeader;
 import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HeaderElement;
 import org.apache.hc.core5.http.HttpHeaders;
 import org.apache.hc.core5.http.HttpMessage;
+import org.apache.hc.core5.http.MessageHeaders;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.CharArrayBuffer;
 import org.apache.hc.core5.util.TextUtils;
@@ -150,4 +153,20 @@ public class MessageSupport {
         }
     }
 
+    public static Iterator<HeaderElement> iterate(final MessageHeaders headers, final String name) {
+        Args.notNull(headers, "Message headers");
+        Args.notBlank(name, "Header name");
+        return new BasicHeaderElementIterator(headers.headerIterator(name));
+    }
+
+    public static HeaderElement[] parse(final Header header) {
+        Args.notNull(header, "Headers");
+        final String value = header.getValue();
+        if (value == null) {
+            return new HeaderElement[] {};
+        }
+        final ParserCursor cursor = new ParserCursor(0, value.length());
+        return BasicHeaderValueParser.INSTANCE.parseElements(value, cursor);
+    }
+
 }

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestTargetHost.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestTargetHost.java?rev=1770475&r1=1770474&r2=1770475&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestTargetHost.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestTargetHost.java Sat Nov 19 09:34:27 2016
@@ -41,6 +41,7 @@ import org.apache.hc.core5.http.HttpRequ
 import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.ProtocolException;
 import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.net.URIAuthority;
 import org.apache.hc.core5.util.Args;
 
 /**
@@ -69,7 +70,7 @@ public class RequestTargetHost implement
         }
 
         if (!request.containsHeader(HttpHeaders.HOST)) {
-            String authority = request.getAuthority();
+            URIAuthority authority = request.getAuthority();
             if (authority == null) {
                 // Populate the context with a default HTTP host based on the
                 // inet address of the target host
@@ -78,7 +79,7 @@ public class RequestTargetHost implement
                 if (conn != null) {
                     final InetSocketAddress remoteAddress = (InetSocketAddress) conn.getRemoteAddress();
                     if (remoteAddress != null) {
-                        authority = remoteAddress.getHostName() + ":" +  remoteAddress.getPort();
+                        authority = new URIAuthority(remoteAddress.getHostName(), remoteAddress.getPort());
                     }
                 }
                 if (authority == null) {
@@ -87,6 +88,10 @@ public class RequestTargetHost implement
                     }
                     throw new ProtocolException("Target host is unknown");
                 }
+            } else {
+                if (authority.getUserInfo() != null) {
+                    authority = new URIAuthority(authority.getHostName(), authority.getPort());
+                }
             }
             request.addHeader(HttpHeaders.HOST, authority);
         }

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestValidateHost.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestValidateHost.java?rev=1770475&r1=1770474&r2=1770475&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestValidateHost.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestValidateHost.java Sat Nov 19 09:34:27 2016
@@ -28,6 +28,7 @@
 package org.apache.hc.core5.http.protocol;
 
 import java.io.IOException;
+import java.net.URISyntaxException;
 
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
@@ -40,12 +41,12 @@ import org.apache.hc.core5.http.HttpRequ
 import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.ProtocolException;
 import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.net.URIAuthority;
 import org.apache.hc.core5.util.Args;
-import org.apache.hc.core5.util.TextUtils;
 
 /**
  * RequestTargetHost is responsible for copying {@code Host} header value to
- * {@link HttpRequest#setAuthority(String)} of the incoming message.
+ * {@link HttpRequest#setAuthority(URIAuthority)} of the incoming message.
  * This interceptor is required for server side protocol processors.
  *
  * @since 5.0
@@ -64,12 +65,13 @@ public class RequestValidateHost impleme
 
         final Header header = request.getSingleHeader(HttpHeaders.HOST);
         if (header != null) {
-            final String authority = header.getValue();
-            if (!TextUtils.isBlank(authority)) {
-                request.setAuthority(authority);
-            } else {
-                throw new ProtocolException("Host header is empty");
+            final URIAuthority authority;
+            try {
+                authority = URIAuthority.create(header.getValue());
+            } catch (URISyntaxException ex) {
+                throw new ProtocolException(ex.getMessage(), ex);
             }
+            request.setAuthority(authority);
         } else {
             final ProtocolVersion version = request.getVersion() != null ? request.getVersion() : HttpVersion.HTTP_1_1;
             if (version.greaterEquals(HttpVersion.HTTP_1_1)) {

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/net/URIAuthority.java (from r1769911, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/net/URIHost.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/net/URIAuthority.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/net/URIAuthority.java&p1=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/net/URIHost.java&r1=1769911&r2=1770475&rev=1770475&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/net/URIHost.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/net/URIAuthority.java Sat Nov 19 09:34:27 2016
@@ -28,37 +28,61 @@
 package org.apache.hc.core5.net;
 
 import java.io.Serializable;
+import java.net.URISyntaxException;
 import java.util.Locale;
 
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.LangUtils;
+import org.apache.hc.core5.util.TextUtils;
 
 /**
- * Represents authority component of HTTP request URI.
+ * Represents authority component of request URI.
  *
  * @since 5.0
  */
 @Contract(threading = ThreadingBehavior.IMMUTABLE)
-public final class URIHost implements NamedEndpoint, Serializable {
+public final class URIAuthority implements NamedEndpoint, Serializable {
 
+    private final String userInfo;
     private final String hostname;
     private final int port;
 
-    public URIHost(final String hostname, final int port) {
+    private URIAuthority(final String userInfo, final String hostname, final int port, final boolean internal) {
         super();
-        this.hostname = Args.containsNoBlanks(hostname, "Host name").toLowerCase(Locale.ROOT);
+        this.userInfo = userInfo;
+        this.hostname = hostname;
         this.port = port;
     }
 
+    public URIAuthority(final String userInfo, final String hostname, final int port) {
+        super();
+        Args.containsNoBlanks(hostname, "Host name");
+        if (userInfo != null) {
+            Args.containsNoBlanks(userInfo, "User info");
+        }
+        this.userInfo = userInfo;
+        this.hostname = hostname.toLowerCase(Locale.ROOT);
+        this.port = port;
+    }
+
+    public URIAuthority(final String hostname, final int port) {
+        this(null, hostname, port);
+    }
+
+    public URIAuthority(final NamedEndpoint namedEndpoint) {
+        this(null, namedEndpoint.getHostName(), namedEndpoint.getPort());
+    }
+
     /**
      * Creates {@code URIHost} instance from string. Text may not contain any blanks.
      */
-    public static URIHost create(final String s) {
+    public static URIAuthority create(final String s) throws URISyntaxException {
         if (s == null) {
             return null;
         }
+        String userInfo = null;
         String hostname = s;
         int port = -1;
         final int portIdx = hostname.lastIndexOf(":");
@@ -66,35 +90,55 @@ public final class URIHost implements Na
             try {
                 port = Integer.parseInt(hostname.substring(portIdx + 1));
             } catch (final NumberFormatException ex) {
-                throw new IllegalArgumentException("Invalid URI host: " + s);
+                throw new URISyntaxException(s, "invalid port");
             }
             hostname = hostname.substring(0, portIdx);
         }
-        return new URIHost(hostname, port);
+        final int atIdx = hostname.lastIndexOf("@");
+        if (atIdx > 0) {
+            userInfo = hostname.substring(0, atIdx);
+            if (TextUtils.containsBlanks(userInfo)) {
+                throw new URISyntaxException(s, "user info contains blanks");
+            }
+            hostname = hostname.substring(atIdx + 1);
+        }
+        if (TextUtils.containsBlanks(hostname)) {
+            throw new URISyntaxException(s, "hostname contains blanks");
+        }
+        return new URIAuthority(userInfo, hostname.toLowerCase(Locale.ROOT), port, true);
     }
 
-    public URIHost(final String hostname) {
-        this(hostname, -1);
+    public URIAuthority(final String hostname) {
+        this(null, hostname, -1);
     }
 
+    public String getUserInfo() {
+        return userInfo;
+    }
+
+    @Override
     public String getHostName() {
-        return this.hostname;
+        return hostname;
     }
 
+    @Override
     public int getPort() {
-        return this.port;
+        return port;
     }
 
     @Override
     public String toString() {
-        if (this.port != -1) {
-            final StringBuilder buffer = new StringBuilder();
-            buffer.append(hostname);
+        final StringBuilder buffer = new StringBuilder();
+        if (userInfo != null) {
+            buffer.append(userInfo);
+            buffer.append("@");
+        }
+        buffer.append(hostname);
+        if (port != -1) {
             buffer.append(":");
             buffer.append(Integer.toString(port));
-            return buffer.toString();
         }
-        return hostname;
+        return buffer.toString();
     }
 
     @Override
@@ -102,9 +146,11 @@ public final class URIHost implements Na
         if (this == obj) {
             return true;
         }
-        if (obj instanceof URIHost) {
-            final URIHost that = (URIHost) obj;
-            return this.hostname.equals(that.hostname) && this.port == that.port;
+        if (obj instanceof URIAuthority) {
+            final URIAuthority that = (URIAuthority) obj;
+            return LangUtils.equals(this.userInfo, that.userInfo) &&
+                    LangUtils.equals(this.hostname, that.hostname) &&
+                    this.port == that.port;
         }
         return false;
     }
@@ -112,8 +158,9 @@ public final class URIHost implements Na
     @Override
     public int hashCode() {
         int hash = LangUtils.HASH_SEED;
-        hash = LangUtils.hashCode(hash, this.hostname);
-        hash = LangUtils.hashCode(hash, this.port);
+        hash = LangUtils.hashCode(hash, userInfo);
+        hash = LangUtils.hashCode(hash, hostname);
+        hash = LangUtils.hashCode(hash, port);
         return hash;
     }
 

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/net/URIAuthority.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/net/URIAuthority.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/net/URIAuthority.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/TestHttpHost.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/TestHttpHost.java?rev=1770475&r1=1770474&r2=1770475&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/TestHttpHost.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/TestHttpHost.java Sat Nov 19 09:34:27 2016
@@ -32,6 +32,7 @@ import java.io.ByteArrayOutputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.net.InetAddress;
+import java.net.URISyntaxException;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -206,13 +207,13 @@ public class TestHttpHost {
     public void testCreateFromStringInvalid() throws Exception {
         try {
             HttpHost.create(" host ");
-            Assert.fail("IllegalArgumentException expected");
-        } catch (final IllegalArgumentException expected) {
+            Assert.fail("URISyntaxException expected");
+        } catch (final URISyntaxException expected) {
         }
         try {
             HttpHost.create("host :8080");
-            Assert.fail("IllegalArgumentException expected");
-        } catch (final IllegalArgumentException expected) {
+            Assert.fail("URISyntaxException expected");
+        } catch (final URISyntaxException expected) {
         }
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/message/TestBasicMessages.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/message/TestBasicMessages.java?rev=1770475&r1=1770474&r2=1770475&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/message/TestBasicMessages.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/message/TestBasicMessages.java Sat Nov 19 09:34:27 2016
@@ -32,6 +32,7 @@ import java.net.URI;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpStatus;
+import org.apache.hc.core5.net.URIAuthority;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -149,7 +150,7 @@ public class TestBasicMessages {
         final HttpRequest request = new BasicHttpRequest("GET", new URI("https://host:9443/stuff?param=value"));
         Assert.assertEquals("GET", request.getMethod());
         Assert.assertEquals("/stuff?param=value", request.getPath());
-        Assert.assertEquals("host:9443", request.getAuthority());
+        Assert.assertEquals(new URIAuthority("host", 9443), request.getAuthority());
         Assert.assertEquals("https", request.getScheme());
         Assert.assertEquals(new URI("https://host:9443/stuff?param=value"), request.getUri());
     }
@@ -159,10 +160,20 @@ public class TestBasicMessages {
         final HttpRequest request = new BasicHttpRequest("GET", new URI("http://host"));
         Assert.assertEquals("GET", request.getMethod());
         Assert.assertEquals("/", request.getPath());
-        Assert.assertEquals("host", request.getAuthority());
+        Assert.assertEquals(new URIAuthority("host"), request.getAuthority());
         Assert.assertEquals("http", request.getScheme());
         Assert.assertEquals(new URI("http://host/"), request.getUri());
     }
 
+    @Test
+    public void testRequestWithUserInfo() throws Exception {
+        final HttpRequest request = new BasicHttpRequest("GET", new URI("https://user:pwd@host:9443/stuff?param=value"));
+        Assert.assertEquals("GET", request.getMethod());
+        Assert.assertEquals("/stuff?param=value", request.getPath());
+        Assert.assertEquals(new URIAuthority("user:pwd", "host", 9443), request.getAuthority());
+        Assert.assertEquals("https", request.getScheme());
+        Assert.assertEquals(new URI("https://host:9443/stuff?param=value"), request.getUri());
+    }
+
 }
 

Modified: httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/protocol/TestStandardInterceptors.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/protocol/TestStandardInterceptors.java?rev=1770475&r1=1770474&r2=1770475&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/protocol/TestStandardInterceptors.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/protocol/TestStandardInterceptors.java Sat Nov 19 09:34:27 2016
@@ -36,7 +36,6 @@ import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HeaderElements;
 import org.apache.hc.core5.http.HttpConnection;
 import org.apache.hc.core5.http.HttpHeaders;
-import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.ProtocolException;
@@ -46,6 +45,7 @@ import org.apache.hc.core5.http.io.entit
 import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
 import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
 import org.apache.hc.core5.http.message.BasicHeader;
+import org.apache.hc.core5.net.URIAuthority;
 import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.Mockito;
@@ -383,9 +383,8 @@ public class TestStandardInterceptors {
     @Test
     public void testRequestTargetHostGenerated() throws Exception {
         final HttpContext context = new BasicHttpContext(null);
-        final HttpHost host = new HttpHost("somehost", 8080, "http");
         final BasicClassicHttpRequest request = new BasicClassicHttpRequest("GET", "/");
-        request.setAuthority(host.toHostString());
+        request.setAuthority(new URIAuthority("somehost", 8080));
         final RequestTargetHost interceptor = new RequestTargetHost();
         interceptor.process(request, request.getEntity(), context);
         final Header header = request.getFirstHeader(HttpHeaders.HOST);
@@ -423,9 +422,8 @@ public class TestStandardInterceptors {
     @Test
     public void testRequestTargetHostNotGenerated() throws Exception {
         final HttpContext context = new BasicHttpContext(null);
-        final HttpHost host = new HttpHost("somehost", 8080, "http");
         final BasicClassicHttpRequest request = new BasicClassicHttpRequest("GET", "/");
-        request.setAuthority(host.toHostString());
+        request.setAuthority(new URIAuthority("somehost", 8080));
         request.addHeader(new BasicHeader(HttpHeaders.HOST, "whatever"));
         final RequestTargetHost interceptor = new RequestTargetHost();
         interceptor.process(request, request.getEntity(), context);
@@ -478,9 +476,8 @@ public class TestStandardInterceptors {
     @Test
     public void testRequestTargetHostConnectHttp11() throws Exception {
         final HttpContext context = new BasicHttpContext(null);
-        final HttpHost host = new HttpHost("somehost", 8080, "http");
         final BasicClassicHttpRequest request = new BasicClassicHttpRequest("CONNECT", "/");
-        request.setAuthority(host.toHostString());
+        request.setAuthority(new URIAuthority("somehost", 8080));
         final RequestTargetHost interceptor = new RequestTargetHost();
         interceptor.process(request, request.getEntity(), context);
         final Header header = request.getFirstHeader(HttpHeaders.HOST);
@@ -492,9 +489,8 @@ public class TestStandardInterceptors {
     public void testRequestTargetHostConnectHttp10() throws Exception {
         final HttpContext context = new BasicHttpContext(null);
         context.setProtocolVersion(HttpVersion.HTTP_1_0);
-        final HttpHost host = new HttpHost("somehost", 8080, "http");
         final BasicClassicHttpRequest request = new BasicClassicHttpRequest("CONNECT", "/");
-        request.setAuthority(host.toHostString());
+        request.setAuthority(new URIAuthority("somehost", 8080));
         final RequestTargetHost interceptor = new RequestTargetHost();
         interceptor.process(request, request.getEntity(), context);
         final Header header = request.getFirstHeader(HttpHeaders.HOST);
@@ -1059,7 +1055,7 @@ public class TestStandardInterceptors {
         request.setHeader(HttpHeaders.HOST, "host:8888");
         final RequestValidateHost interceptor = new RequestValidateHost();
         interceptor.process(request, request.getEntity(), context);
-        Assert.assertEquals("host:8888", request.getAuthority());
+        Assert.assertEquals(new URIAuthority("host", 8888), request.getAuthority());
     }
 
     @Test
@@ -1070,7 +1066,7 @@ public class TestStandardInterceptors {
         request.setHeader(HttpHeaders.HOST, "host");
         final RequestValidateHost interceptor = new RequestValidateHost();
         interceptor.process(request, request.getEntity(), context);
-        Assert.assertEquals("host", request.getAuthority());
+        Assert.assertEquals(new URIAuthority("host"), request.getAuthority());
     }
 
     @Test

Copied: httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIAuthority.java (from r1769911, httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIHost.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIAuthority.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIAuthority.java&p1=httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIHost.java&r1=1769911&r2=1770475&rev=1770475&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIHost.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIAuthority.java Sat Nov 19 09:34:27 2016
@@ -31,72 +31,81 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
+import java.net.URISyntaxException;
 
 import org.junit.Assert;
 import org.junit.Test;
 
 /**
- * Unit tests for {@link URIHost}.
+ * Unit tests for {@link URIAuthority}.
  *
  */
-public class TestURIHost {
+public class TestURIAuthority {
 
     @Test
     public void testConstructor() {
-        final URIHost host1 = new URIHost("somehost");
+        final URIAuthority host1 = new URIAuthority("somehost");
         Assert.assertEquals("somehost", host1.getHostName());
         Assert.assertEquals(-1, host1.getPort());
-        final URIHost host2 = new URIHost("somehost", 8080);
+        final URIAuthority host2 = new URIAuthority("somehost", 8080);
         Assert.assertEquals("somehost", host2.getHostName());
         Assert.assertEquals(8080, host2.getPort());
-        final URIHost host3 = new URIHost("somehost", -1);
+        final URIAuthority host3 = new URIAuthority("somehost", -1);
         Assert.assertEquals("somehost", host3.getHostName());
         Assert.assertEquals(-1, host3.getPort());
     }
 
     @Test
     public void testHashCode() throws Exception {
-        final URIHost host1 = new URIHost("somehost", 8080);
-        final URIHost host2 = new URIHost("somehost", 80);
-        final URIHost host3 = new URIHost("someotherhost", 8080);
-        final URIHost host4 = new URIHost("somehost", 80);
-        final URIHost host5 = new URIHost("SomeHost", 80);
+        final URIAuthority host1 = new URIAuthority("somehost", 8080);
+        final URIAuthority host2 = new URIAuthority("somehost", 80);
+        final URIAuthority host3 = new URIAuthority("someotherhost", 8080);
+        final URIAuthority host4 = new URIAuthority("somehost", 80);
+        final URIAuthority host5 = new URIAuthority("SomeHost", 80);
+        final URIAuthority host6 = new URIAuthority("user", "SomeHost", 80);
+        final URIAuthority host7 = new URIAuthority("user", "somehost", 80);
 
         Assert.assertTrue(host1.hashCode() == host1.hashCode());
         Assert.assertTrue(host1.hashCode() != host2.hashCode());
         Assert.assertTrue(host1.hashCode() != host3.hashCode());
         Assert.assertTrue(host2.hashCode() == host4.hashCode());
         Assert.assertTrue(host2.hashCode() == host5.hashCode());
+        Assert.assertTrue(host5.hashCode() != host6.hashCode());
+        Assert.assertTrue(host6.hashCode() == host7.hashCode());
     }
 
     @Test
     public void testEquals() throws Exception {
-        final URIHost host1 = new URIHost("somehost", 8080);
-        final URIHost host2 = new URIHost("somehost", 80);
-        final URIHost host3 = new URIHost("someotherhost", 8080);
-        final URIHost host4 = new URIHost("somehost", 80);
-        final URIHost host5 = new URIHost("SomeHost", 80);
+        final URIAuthority host1 = new URIAuthority("somehost", 8080);
+        final URIAuthority host2 = new URIAuthority("somehost", 80);
+        final URIAuthority host3 = new URIAuthority("someotherhost", 8080);
+        final URIAuthority host4 = new URIAuthority("somehost", 80);
+        final URIAuthority host5 = new URIAuthority("SomeHost", 80);
+        final URIAuthority host6 = new URIAuthority("user", "SomeHost", 80);
+        final URIAuthority host7 = new URIAuthority("user", "somehost", 80);
 
         Assert.assertTrue(host1.equals(host1));
         Assert.assertFalse(host1.equals(host2));
         Assert.assertFalse(host1.equals(host3));
         Assert.assertTrue(host2.equals(host4));
         Assert.assertTrue(host2.equals(host5));
+        Assert.assertFalse(host5.equals(host6));
+        Assert.assertTrue(host6.equals(host7));
     }
 
     @Test
     public void testToString() throws Exception {
-        final URIHost host1 = new URIHost("somehost");
+        final URIAuthority host1 = new URIAuthority("somehost");
         Assert.assertEquals("somehost", host1.toString());
-        final URIHost host2 = new URIHost("somehost", -1);
+        final URIAuthority host2 = new URIAuthority("somehost", -1);
         Assert.assertEquals("somehost", host2.toString());
-        final URIHost host3 = new URIHost("somehost", 8888);
+        final URIAuthority host3 = new URIAuthority("somehost", 8888);
         Assert.assertEquals("somehost:8888", host3.toString());
     }
 
     @Test
     public void testSerialization() throws Exception {
-        final URIHost orig = new URIHost("somehost", 8080);
+        final URIAuthority orig = new URIAuthority("somehost", 8080);
         final ByteArrayOutputStream outbuffer = new ByteArrayOutputStream();
         final ObjectOutputStream outstream = new ObjectOutputStream(outbuffer);
         outstream.writeObject(orig);
@@ -104,29 +113,35 @@ public class TestURIHost {
         final byte[] raw = outbuffer.toByteArray();
         final ByteArrayInputStream inbuffer = new ByteArrayInputStream(raw);
         final ObjectInputStream instream = new ObjectInputStream(inbuffer);
-        final URIHost clone = (URIHost) instream.readObject();
+        final URIAuthority clone = (URIAuthority) instream.readObject();
         Assert.assertEquals(orig, clone);
     }
 
     @Test
     public void testCreateFromString() throws Exception {
-        Assert.assertEquals(new URIHost("somehost", 8080), URIHost.create("somehost:8080"));
-        Assert.assertEquals(new URIHost("somehost", 8080), URIHost.create("SomeHost:8080"));
-        Assert.assertEquals(new URIHost("somehost", 1234), URIHost.create("somehost:1234"));
-        Assert.assertEquals(new URIHost("somehost", -1), URIHost.create("somehost"));
+        Assert.assertEquals(new URIAuthority("somehost", 8080), URIAuthority.create("somehost:8080"));
+        Assert.assertEquals(new URIAuthority("somehost", 8080), URIAuthority.create("SomeHost:8080"));
+        Assert.assertEquals(new URIAuthority("somehost", 1234), URIAuthority.create("somehost:1234"));
+        Assert.assertEquals(new URIAuthority("somehost", -1), URIAuthority.create("somehost"));
+        Assert.assertEquals(new URIAuthority("user", "somehost", -1), URIAuthority.create("user@somehost"));
     }
 
     @Test
     public void testCreateFromStringInvalid() throws Exception {
         try {
-            URIHost.create(" host ");
+            URIAuthority.create(" host ");
             Assert.fail("IllegalArgumentException expected");
-        } catch (final IllegalArgumentException expected) {
+        } catch (final URISyntaxException expected) {
         }
         try {
-            URIHost.create("host :8080");
-            Assert.fail("IllegalArgumentException expected");
-        } catch (final IllegalArgumentException expected) {
+            URIAuthority.create("host :8080");
+            Assert.fail("URISyntaxException expected");
+        } catch (final URISyntaxException expected) {
+        }
+        try {
+            URIAuthority.create("user @ host:8080");
+            Assert.fail("URISyntaxException expected");
+        } catch (final URISyntaxException expected) {
         }
     }
 

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIAuthority.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIAuthority.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIAuthority.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain