Allow to add exec interceptor as the first and the last

Closes PR #76
This commit is contained in:
Pavol Loffay 2017-05-09 14:58:58 +02:00 committed by Oleg Kalnichevski
parent b5b39efd72
commit 4bd79fb3dd
2 changed files with 54 additions and 2 deletions

View File

@ -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;
}
}
}

View File

@ -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;
}
}
}