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/13 14:09:58 UTC

svn commit: r1769500 - in /httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/message: BasicHttpRequest.java BasicHttpResponse.java

Author: olegk
Date: Sun Nov 13 14:09:58 2016
New Revision: 1769500

URL: http://svn.apache.org/viewvc?rev=1769500&view=rev
Log:
BasicHttpRequest optimization; code cleanup

Modified:
    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/BasicHttpResponse.java

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=1769500&r1=1769499&r2=1769500&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 Sun Nov 13 14:09:58 2016
@@ -30,7 +30,6 @@ package org.apache.hc.core5.http.message
 import java.net.URI;
 import java.net.URISyntaxException;
 
-import org.apache.hc.core5.http.HttpEntity;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.ProtocolVersion;
@@ -51,7 +50,7 @@ public class BasicHttpRequest extends He
     private String scheme;
     private String authority;
     private ProtocolVersion version;
-    private HttpEntity entity;
+    private URI requestUri;
 
     /**
      * Creates request message with the given method and request path.
@@ -141,8 +140,9 @@ public class BasicHttpRequest extends He
     }
 
     @Override
-    public void setPath(final String requestUri) {
-        this.path = requestUri;
+    public void setPath(final String path) {
+        this.path = path;
+        this.requestUri = null;
     }
 
     @Override
@@ -153,6 +153,7 @@ public class BasicHttpRequest extends He
     @Override
     public void setScheme(final String scheme) {
         this.scheme = scheme;
+        this.requestUri = null;
     }
 
     @Override
@@ -163,23 +164,26 @@ public class BasicHttpRequest extends He
     @Override
     public void setAuthority(final String authority) {
         this.authority = authority;
+        this.requestUri = null;
     }
 
     @Override
     public URI getUri() throws URISyntaxException {
-        final StringBuilder buf = new StringBuilder();
-        if (this.authority != null) {
-            buf.append(this.scheme != null ? this.scheme : "http").append("://").append(this.authority);
+        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.path != null ? this.path : "/");
+            this.requestUri = new URI(buf.toString());
         }
-        buf.append(this.path != null ? this.path : "/");
-        return new URI(buf.toString());
+        return this.requestUri;
     }
 
     @Override
     public String toString() {
         final StringBuilder sb = new StringBuilder();
-        sb.append(this.method).append(" ").append(this.scheme).append("://").append(this.authority).append("/").append(this.path).append(" ")
-                .append(super.toString());
+        sb.append(this.method).append(" ").append(this.scheme).append("://").append(this.authority).append("/").append(this.path);
         return sb.toString();
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicHttpResponse.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicHttpResponse.java?rev=1769500&r1=1769499&r2=1769500&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicHttpResponse.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicHttpResponse.java Sun Nov 13 14:09:58 2016
@@ -29,7 +29,6 @@ package org.apache.hc.core5.http.message
 
 import java.util.Locale;
 
-import org.apache.hc.core5.http.HttpEntity;
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.ProtocolVersion;
 import org.apache.hc.core5.http.ReasonPhraseCatalog;
@@ -51,7 +50,6 @@ public class BasicHttpResponse extends H
     private Locale locale;
     private int code;
     private String reasonPhrase;
-    private HttpEntity entity;
 
     /**
      * Creates a new response.
@@ -167,7 +165,7 @@ public class BasicHttpResponse extends H
     @Override
     public String toString() {
         final StringBuilder sb = new StringBuilder();
-        sb.append(this.code).append(" ").append(this.code).append(this.reasonPhrase).append(" ").append(super.toString());
+        sb.append(this.code).append(" ").append(this.code).append(this.reasonPhrase);
         return sb.toString();
     }