Skip to content

Instantly share code, notes, and snippets.

@brianm
Created December 8, 2016 17:04
Show Gist options
  • Save brianm/5358a1aa3e39b0ffe3467e19e4ec740c to your computer and use it in GitHub Desktop.
Save brianm/5358a1aa3e39b0ffe3467e19e4ec740c to your computer and use it in GitHub Desktop.
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