Repository navigation
Issue-6 Support custom interceptors #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,15 +55,20 @@ private Retrofit.Builder createRetrofitBuilder(CommunicationConfig config) { | |
| } | ||
|
|
||
| private OkHttpClient createOkHttpClient(CommunicationConfig config) { | ||
| return new OkHttpClient.Builder() | ||
| OkHttpClient.Builder builder = new OkHttpClient.Builder() | ||
| .addInterceptor(new HeadersInterceptor(config.getHeaders())) | ||
| .addInterceptor(createLoggingInterceptor(config)) | ||
| .readTimeout(config.getReadTimeoutMillis(), TimeUnit.MILLISECONDS) | ||
| .writeTimeout(config.getWriteTimeoutMillis(), TimeUnit.MILLISECONDS) | ||
| .connectTimeout(config.getConnectionTimeoutMillis(), TimeUnit.MILLISECONDS) | ||
| .connectionPool(new ConnectionPool(config.getMaxIdleConnections(), | ||
| config.getKeepAliveDurationMillis(), TimeUnit.MILLISECONDS)) | ||
| .build(); | ||
| config.getKeepAliveDurationMillis(), TimeUnit.MILLISECONDS)); | ||
|
|
||
| if (config.getInterceptors() != null) { | ||
| config.getInterceptors().forEach(builder::addInterceptor); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I afraid of such a wide access to API protocol, I thought better to add some "safe" AroundAspect like interceptor which will be safe not to break API calls but allow different before/after code parts.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When do you think the aspect oriented flows would be in place? I wonder how it will be implemented.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe meanwhile we can create something simple to allow interceptors but limit them to specific code parts like "beforeCall", "afterCall" you can do by creating dedicated interface and create one general interceptor that run list of such interfaces and let developer use those which will both limit the exposure of internal flows vs give enough abilities to save things or log or etc. WDYT?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is fine, as long as the new interface provides access to the request and response.. if it does not, then this dummy interceptor might be useless. so basically could be an interface like: public interface Interceptor { } WDYT?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can provide both request and response data we just need to plan what response should contain, for example raw Retrofit response is problematic since you dont know which call adapter is handling it since interceptors happening before call adapter. For example I think that those provided "before/after" code injection parts can not manipulate request nor response so both request and response references should be immutable. |
||
| } | ||
|
|
||
| return builder.build(); | ||
| } | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
best to avoid coupling to okhttp3 so I prefer creating our own dedicated Interceptor interface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, good point.