hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject httpcomponents-core git commit: HTTPCORE-475: minor improvements in the classic i/o reverse proxy example
Date Sun, 02 Jul 2017 18:47:48 GMT
Repository: httpcomponents-core
Updated Branches:
  refs/heads/4.4.x 3a4fe27af -> 219b55b07


HTTPCORE-475: minor improvements in the classic i/o reverse proxy example


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

Branch: refs/heads/4.4.x
Commit: 219b55b0702ce4dc6dbcb2ba178f0eb2930aab11
Parents: 3a4fe27
Author: Oleg Kalnichevski <olegk@apache.org>
Authored: Sun Jul 2 20:45:00 2017 +0200
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Sun Jul 2 20:45:41 2017 +0200

----------------------------------------------------------------------
 .../apache/http/examples/ElementalReverseProxy.java   | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/219b55b0/httpcore/src/examples/org/apache/http/examples/ElementalReverseProxy.java
----------------------------------------------------------------------
diff --git a/httpcore/src/examples/org/apache/http/examples/ElementalReverseProxy.java b/httpcore/src/examples/org/apache/http/examples/ElementalReverseProxy.java
index bf442df..5c7e899 100644
--- a/httpcore/src/examples/org/apache/http/examples/ElementalReverseProxy.java
+++ b/httpcore/src/examples/org/apache/http/examples/ElementalReverseProxy.java
@@ -74,17 +74,18 @@ public class ElementalReverseProxy {
 
     public static void main(final String[] args) throws Exception {
         if (args.length < 1) {
-            System.err.println("Please specified target hostname and port");
+            System.out.println("Usage: <hostname[:port]> [listener port]");
             System.exit(1);
         }
-        final String hostname = args[0];
-        int port = 80;
+        final HttpHost targetHost = HttpHost.create(args[0]);
+        int port = 8080;
         if (args.length > 1) {
             port = Integer.parseInt(args[1]);
         }
-        final HttpHost target = new HttpHost(hostname, port);
 
-        final Thread t = new RequestListenerThread(8888, target);
+        System.out.println("Reverse proxy to " + targetHost);
+
+        final Thread t = new RequestListenerThread(port, targetHost);
         t.setDaemon(false);
         t.start();
     }
@@ -121,6 +122,7 @@ public class ElementalReverseProxy {
             System.out.println(">> Request URI: " + request.getRequestLine().getUri());
 
             // Remove hop-by-hop headers
+            request.removeHeaders(HTTP.TARGET_HOST);
             request.removeHeaders(HTTP.CONTENT_LEN);
             request.removeHeaders(HTTP.TRANSFER_ENCODING);
             request.removeHeaders(HTTP.CONN_DIRECTIVE);
@@ -207,7 +209,7 @@ public class ElementalReverseProxy {
                     inconn.bind(insocket);
 
                     // Set up outgoing HTTP connection
-                    final Socket outsocket = new Socket(this.target.getHostName(), this.target.getPort());
+                    final Socket outsocket = new Socket(this.target.getHostName(), this.target.getPort()
>= 0 ? this.target.getPort() : 80);
                     final DefaultBHttpClientConnection outconn = new DefaultBHttpClientConnection(bufsize);
                     outconn.bind(outsocket);
                     System.out.println("Outgoing connection to " + outsocket.getInetAddress());


Mime
View raw message