You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by gg...@apache.org on 2017/05/18 06:10:17 UTC

httpcomponents-core git commit: [HTTPCORE-468]: Allow HttpAsyncService subclasses to customize the HTTP status code.

Repository: httpcomponents-core
Updated Branches:
  refs/heads/dev/5.0.x/HTTPCORE-468 [created] 789410f47


[HTTPCORE-468]: Allow HttpAsyncService subclasses to customize the HTTP
status code.

Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/789410f4
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/789410f4
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/789410f4

Branch: refs/heads/dev/5.0.x/HTTPCORE-468
Commit: 789410f4779b9bb18a25c320c5ced1e215397fc3
Parents: 8099ed1
Author: Gary Gregory <gg...@apache.org>
Authored: Wed May 17 23:10:11 2017 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Wed May 17 23:10:11 2017 -0700

----------------------------------------------------------------------
 RELEASE_NOTES.txt                               | 59 ++++++++++++++++++++
 .../hc/core5/http/impl/io/HttpService.java      | 27 +++++----
 .../http/impl/nio/ServerHttp1StreamHandler.java | 14 +++--
 3 files changed, 84 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/789410f4/RELEASE_NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index 7c1c829..5725aaa 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -1,3 +1,62 @@
+Release 5.0-ALPHA4
+-------------------
+
+This is a major release that renders HttpCore API incompatible with the stable 4.x branch
+and upgrades HTTP/1.1 and HTTP/2 protocol conformance to the requirements and recommendations
+of the latest protocol specification.
+
+Notable changes and features included in the 5.0 series are:
+
+* Partial support for HTTP/2 protocol and conformance to requirements and
+  recommendations of the latest HTTP/2 protocol specification (RFC 7540, RFC 7541)
+
+  Supported features:
+
+    ** HPACK header compression
+    ** stream multiplexing (client and server)
+    ** flow control
+    ** response push (client and server)
+    ** message trailers
+    ** expect-continue handshake
+    ** connection validation (ping)
+    ** application-layer protocol negotiation (ALPN) on Java 1.9+
+    ** TLS 1.2 security features
+
+   Unsupported features:
+
+    ** padding of outgoing frames
+    ** stream priority
+    ** plain connection HTTP/1.1 upgrade
+    ** CONNECT method
+
+* Improved conformance to requirements and recommendations of the latest HTTP/1.1 protocol
+  specification (RFC 7230, RFC 7231)
+
+* New asynchronous HTTP transport APIs consistent for both HTTP/1.1 and HTTP/2 transport.
+
+* Improved HTTP/1.1 and HTTP/2 requester and server implementations.
+
+* Redesigned connection pool implementation with reduced pool lock contention.
+
+* Plug-in mechanism for HTTP/1.1 protocol switch / upgrade.
+
+* Package name space changed to 'org.apache.hc.core5'
+
+* Maven group id changed to 'org.apache.httpcomponents.core5'
+
+HttpCore 5.0 releases can be co-located with earlier versions.
+
+Please note that as of 5.0 HttpCore requires Java 1.7 or newer.
+
+Please note that at this point 5.0 APIs are considered API experimental and unstable and are
+expected to change in the coming releases without providing a migration path.
+
+Changelog
+-------------------
+
+* HTTPCORE-468: Allow HttpAsyncService subclasses to customize the HTTP status code.
+
+
 Release 5.0-ALPHA3
 -------------------
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/789410f4/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpService.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpService.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpService.java
index b0efe13..216d1f4 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpService.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpService.java
@@ -267,23 +267,28 @@ public class HttpService {
      * @param response the HTTP response.
      */
     protected void handleException(final HttpException ex, final ClassicHttpResponse response) {
+        response.setCode(toStatusCode(ex, response));
+        String message = ex.getMessage();
+        if (message == null) {
+            message = ex.toString();
+        }
+        response.setEntity(new StringEntity(message, ContentType.TEXT_PLAIN));
+    }
+
+    protected int toStatusCode(final Exception ex, final ClassicHttpResponse response) {
+        final int code;
         if (ex instanceof MethodNotSupportedException) {
-            response.setCode(HttpStatus.SC_NOT_IMPLEMENTED);
+            code = HttpStatus.SC_NOT_IMPLEMENTED;
         } else if (ex instanceof UnsupportedHttpVersionException) {
-            response.setCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED);
+            code = HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED;
         } else if (ex instanceof NotImplementedException) {
-            response.setCode(HttpStatus.SC_NOT_IMPLEMENTED);
+            code = HttpStatus.SC_NOT_IMPLEMENTED;
         } else if (ex instanceof ProtocolException) {
-            response.setCode(HttpStatus.SC_BAD_REQUEST);
+            code = HttpStatus.SC_BAD_REQUEST;
         } else {
-            response.setCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
-        }
-        String message = ex.getMessage();
-        if (message == null) {
-            message = ex.toString();
+            code = HttpStatus.SC_INTERNAL_SERVER_ERROR;
         }
-        final StringEntity entity = new StringEntity(message, ContentType.TEXT_PLAIN);
-        response.setEntity(entity);
+        return code;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/789410f4/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
index 8bafa4c..7b2b698 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
@@ -206,6 +206,14 @@ class ServerHttp1StreamHandler implements ResourceHolder {
     }
 
     AsyncResponseProducer handleException(final Exception ex) {
+        String message = ex.getMessage();
+        if (message == null) {
+            message = ex.toString();
+        }
+        return new BasicResponseProducer(toStatusCode(ex), message);
+    }
+
+    protected int toStatusCode(final Exception ex) {
         final int code;
         if (ex instanceof MethodNotSupportedException) {
             code = HttpStatus.SC_NOT_IMPLEMENTED;
@@ -218,11 +226,7 @@ class ServerHttp1StreamHandler implements ResourceHolder {
         } else {
             code = HttpStatus.SC_INTERNAL_SERVER_ERROR;
         }
-        String message = ex.getMessage();
-        if (message == null) {
-            message = ex.toString();
-        }
-        return new BasicResponseProducer(code, message);
+        return code;
     }
 
     void consumeHeader(final HttpRequest request, final boolean requestEndStream) throws HttpException, IOException {