use of okhttp3.Request.Builder in project Tusky by tuskyapp.
the class InstanceSwitchAuthInterceptor method intercept.
@Override
public Response intercept(@NonNull Chain chain) throws IOException {
Request originalRequest = chain.request();
AccountEntity currentAccount = accountManager.getActiveAccount();
Request.Builder builder = originalRequest.newBuilder();
String instanceHeader = originalRequest.header(MastodonApi.DOMAIN_HEADER);
if (instanceHeader != null) {
// use domain explicitly specified in custom header
builder.url(swapHost(originalRequest.url(), instanceHeader));
builder.removeHeader(MastodonApi.DOMAIN_HEADER);
} else if (currentAccount != null) {
// use domain of current account
builder.url(swapHost(originalRequest.url(), currentAccount.getDomain())).header("Authorization", String.format("Bearer %s", currentAccount.getAccessToken()));
}
Request newRequest = builder.build();
return chain.proceed(newRequest);
}
use of okhttp3.Request.Builder in project lzc_app_lib by httplzc.
the class HttpUtil method download.
// 下载文件
public static void download(String url, RequestParams params, FileDownloadCallBack fileDownloadCallBack, Object tag) {
if (!validUrl(url)) {
fileDownloadCallBack.onFailure(Invalid, null);
return;
}
HttpUrl httpUrl = formatUrl(params, url);
if (httpUrl == null) {
fileDownloadCallBack.onFailure(Invalid, null);
return;
}
try {
Request.Builder builder = new Request.Builder().url(httpUrl).tag(tag);
if (params != null)
for (Map.Entry<String, String> stringStringEntry : params.getHeads().entrySet()) {
builder.addHeader(stringStringEntry.getKey(), stringStringEntry.getValue());
}
Request request = builder.build();
OkHttpInstance.getClient().newCall(request).enqueue(fileDownloadCallBack);
} catch (Exception e) {
e.printStackTrace();
}
}
use of okhttp3.Request.Builder in project lzc_app_lib by httplzc.
the class HttpUtil method get.
/**
* get 有参数
*
* @param urlString
* @param params
* @param responseHandler
*/
public static void get(String urlString, RequestParams params, Callback responseHandler, Object tag) {
HttpUrl httpUrl = formatUrl(params, urlString);
if (httpUrl == null) {
responseHandler.onFailure(null, null);
return;
}
try {
Request.Builder builder = new Request.Builder().url(httpUrl).tag(tag);
if (params != null) {
for (Map.Entry<String, String> stringStringEntry : params.getHeads().entrySet()) {
builder.addHeader(stringStringEntry.getKey(), stringStringEntry.getValue());
}
}
Request request = builder.build();
OkHttpInstance.getClient().newCall(request).enqueue(responseHandler);
} catch (Exception e) {
e.printStackTrace();
}
}
use of okhttp3.Request.Builder in project crnk-framework by crnk-project.
the class OkHttpAdapter method initImpl.
private synchronized void initImpl() {
if (impl == null) {
Builder builder = new OkHttpClient.Builder();
if (networkTimeout != null) {
builder.readTimeout(networkTimeout, TimeUnit.MILLISECONDS);
}
for (OkHttpAdapterListener listener : listeners) {
listener.onBuild(builder);
}
impl = builder.build();
}
}
use of okhttp3.Request.Builder in project crnk-framework by crnk-project.
the class AbstractMetaJerseyTest method setNetworkTimeout.
public static void setNetworkTimeout(CrnkClient client, final int timeout, final TimeUnit timeUnit) {
OkHttpAdapter httpAdapter = (OkHttpAdapter) client.getHttpAdapter();
httpAdapter.addListener(new OkHttpAdapterListenerBase() {
@Override
public void onBuild(Builder builder) {
builder.readTimeout(timeout, timeUnit);
}
});
}
Aggregations