hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject httpcomponents-client git commit: Allow to add exec interceptor as the first and the last
Date Thu, 18 May 2017 07:30:07 GMT
Repository: httpcomponents-client
Updated Branches:
  refs/heads/master b5b39efd7 -> 4bd79fb3d


Allow to add exec interceptor as the first and the last

Closes PR #76


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/commit/4bd79fb3
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/tree/4bd79fb3
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/diff/4bd79fb3

Branch: refs/heads/master
Commit: 4bd79fb3dde9667104f23490c31820bf0f96f328
Parents: b5b39ef
Author: Pavol Loffay <ploffay@redhat.com>
Authored: Tue May 9 14:58:58 2017 +0200
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Thu May 18 09:27:58 2017 +0200

----------------------------------------------------------------------
 .../http/impl/async/HttpAsyncClientBuilder.java | 28 +++++++++++++++++++-
 .../http/impl/sync/HttpClientBuilder.java       | 28 +++++++++++++++++++-
 2 files changed, 54 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/4bd79fb3/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java
b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java
index 619efca..0a7e02d 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java
@@ -176,7 +176,7 @@ public class HttpAsyncClientBuilder {
 
     private static class ExecInterceptorEntry {
 
-        enum Postion { BEFORE, AFTER, REPLACE }
+        enum Postion { BEFORE, AFTER, REPLACE, FIRST, LAST }
 
         final ExecInterceptorEntry.Postion postion;
         final String name;
@@ -431,6 +431,26 @@ public class HttpAsyncClientBuilder {
     }
 
     /**
+     * Add an interceptor to the head of the processing list.
+     */
+    public final HttpAsyncClientBuilder addExecInterceptorFirst(final String name, final
AsyncExecChainHandler interceptor) {
+        Args.notNull(name, "Name");
+        Args.notNull(interceptor, "Interceptor");
+        execInterceptors.add(new ExecInterceptorEntry(ExecInterceptorEntry.Postion.FIRST,
name, interceptor, null));
+        return this;
+    }
+
+    /**
+     * Add an interceptor to the tail of the processing list.
+     */
+    public final HttpAsyncClientBuilder addExecInterceptorLast(final String name, final AsyncExecChainHandler
interceptor) {
+        Args.notNull(name, "Name");
+        Args.notNull(interceptor, "Interceptor");
+        execInterceptors.add(new ExecInterceptorEntry(ExecInterceptorEntry.Postion.LAST,
name, interceptor, null));
+        return this;
+    }
+
+    /**
      * Adds this protocol interceptor to the head of the protocol processing list.
      */
     public final HttpAsyncClientBuilder addRequestInterceptorFirst(final HttpRequestInterceptor
interceptor) {
@@ -913,6 +933,12 @@ public class HttpAsyncClientBuilder {
                     case BEFORE:
                         execChainDefinition.addBefore(entry.existing, entry.interceptor,
entry.name);
                         break;
+                    case FIRST:
+                        execChainDefinition.addFirst(entry.interceptor, entry.name);
+                        break;
+                    case LAST:
+                        execChainDefinition.addLast(entry.interceptor, entry.name);
+                        break;
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/4bd79fb3/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java
b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java
index 4ec65a4..af94d36 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java
@@ -163,7 +163,7 @@ public class HttpClientBuilder {
 
     private static class ExecInterceptorEntry {
 
-        enum Postion { BEFORE, AFTER, REPLACE }
+        enum Postion { BEFORE, AFTER, REPLACE, FIRST, LAST }
 
         final Postion postion;
         final String name;
@@ -444,6 +444,26 @@ public class HttpClientBuilder {
     }
 
     /**
+     * Add an interceptor to the head of the processing list.
+     */
+    public final HttpClientBuilder addExecInterceptorFirst(final String name, final ExecChainHandler
interceptor) {
+        Args.notNull(name, "Name");
+        Args.notNull(interceptor, "Interceptor");
+        execInterceptors.add(new ExecInterceptorEntry(ExecInterceptorEntry.Postion.FIRST,
name, interceptor, null));
+        return this;
+    }
+
+    /**
+     * Add an interceptor to the tail of the processing list.
+     */
+    public final HttpClientBuilder addExecInterceptorLast(final String name, final ExecChainHandler
interceptor) {
+        Args.notNull(name, "Name");
+        Args.notNull(interceptor, "Interceptor");
+        execInterceptors.add(new ExecInterceptorEntry(ExecInterceptorEntry.Postion.LAST,
name, interceptor, null));
+        return this;
+    }
+
+    /**
      * Disables state (cookie) management.
      */
     public final HttpClientBuilder disableCookieManagement() {
@@ -902,6 +922,12 @@ public class HttpClientBuilder {
                     case REPLACE:
                         execChainDefinition.replace(entry.existing, entry.interceptor);
                         break;
+                    case FIRST:
+                        execChainDefinition.addFirst(entry.interceptor, entry.name);
+                        break;
+                    case LAST:
+                        execChainDefinition.addLast(entry.interceptor, entry.name);
+                        break;
                 }
             }
         }


Mime
View raw message