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 619efcac4..0a7e02d48 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 @@ private ResponseInterceptorEntry(final ResponseInterceptorEntry.Postion postion, private static class ExecInterceptorEntry { - enum Postion { BEFORE, AFTER, REPLACE } + enum Postion { BEFORE, AFTER, REPLACE, FIRST, LAST } final ExecInterceptorEntry.Postion postion; final String name; @@ -430,6 +430,26 @@ public final HttpAsyncClientBuilder replaceExecInterceptor(final String existing return this; } + /** + * 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. */ @@ -913,6 +933,12 @@ public void execute(final IOSession ioSession) { 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; } } } 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 4ec65a4d2..af94d360c 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 @@ private ResponseInterceptorEntry(final Postion postion, final HttpResponseInterc private static class ExecInterceptorEntry { - enum Postion { BEFORE, AFTER, REPLACE } + enum Postion { BEFORE, AFTER, REPLACE, FIRST, LAST } final Postion postion; final String name; @@ -443,6 +443,26 @@ public final HttpClientBuilder replaceExecInterceptor(final String existing, fin return this; } + /** + * 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. */ @@ -902,6 +922,12 @@ public boolean keepAlive( 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; } } }