Created
December 8, 2016 17:04
-
-
Save brianm/5358a1aa3e39b0ffe3467e19e4ec740c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HttpClient implements Call.Factory { | |
private final OkHttpClient ok; | |
HttpClient(final OkHttpClient ok) { | |
this.ok = ok; | |
} | |
/** | |
* Returns a CompletableCall, which supports CompletableFuture based enqueueing. | |
*/ | |
public CompletableCall newCall(final Request request) { | |
return newCall(Ctx.fromThread().orElseGet(Ctx::empty), request); | |
} | |
/** | |
* Returns a CompletableCall, which supports CompletableFuture based enqueueing | |
*/ | |
public CompletableCall newCall(Ctx ctx, final Request request) { | |
OkHttpClient.Builder b = this.ok.newBuilder(); | |
b.interceptors().add(0, new CtxInterceptor(ctx)); | |
return new CompletableCall(ctx, b.build().newCall(request)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment