use of com.kymjs.rxvolley.http.URLHttpResponse in project yoo_home_Android by culturer.
the class OkHttpStack method performRequest.
@Override
public URLHttpResponse performRequest(Request<?> request, ArrayList<HttpParamsEntry> additionalHeaders) throws IOException {
OkHttpClient client = mClient.clone();
int timeoutMs = request.getTimeoutMs();
client.setConnectTimeout(timeoutMs, TimeUnit.MILLISECONDS);
client.setReadTimeout(timeoutMs, TimeUnit.MILLISECONDS);
client.setWriteTimeout(timeoutMs, TimeUnit.MILLISECONDS);
com.squareup.okhttp.Request.Builder okHttpRequestBuilder = new com.squareup.okhttp.Request.Builder();
okHttpRequestBuilder.url(request.getUrl());
for (final HttpParamsEntry entry : request.getHeaders()) {
okHttpRequestBuilder.addHeader(entry.k, entry.v);
}
for (final HttpParamsEntry entry : additionalHeaders) {
okHttpRequestBuilder.addHeader(entry.k, entry.v);
}
setConnectionParametersForRequest(okHttpRequestBuilder, request);
com.squareup.okhttp.Request okHttpRequest = okHttpRequestBuilder.build();
Call okHttpCall = client.newCall(okHttpRequest);
Response okHttpResponse = okHttpCall.execute();
return responseFromConnection(okHttpResponse);
}
use of com.kymjs.rxvolley.http.URLHttpResponse in project yoo_home_Android by culturer.
the class OkHttpStack method responseFromConnection.
private URLHttpResponse responseFromConnection(Response okHttpResponse) throws IOException {
URLHttpResponse response = new URLHttpResponse();
// contentStream
int responseCode = okHttpResponse.code();
if (responseCode == -1) {
throw new IOException("Could not retrieve response code from HttpUrlConnection.");
}
response.setResponseCode(responseCode);
response.setResponseMessage(okHttpResponse.message());
response.setContentStream(okHttpResponse.body().byteStream());
response.setContentLength(okHttpResponse.body().contentLength());
response.setContentEncoding(okHttpResponse.header("Content-Encoding"));
if (okHttpResponse.body().contentType() != null) {
response.setContentType(okHttpResponse.body().contentType().type());
}
// header
HashMap<String, String> headerMap = new HashMap<>();
Headers responseHeaders = okHttpResponse.headers();
for (int i = 0, len = responseHeaders.size(); i < len; i++) {
final String name = responseHeaders.name(i), value = responseHeaders.value(i);
if (name != null) {
headerMap.put(name, value);
}
}
response.setHeaders(headerMap);
return response;
}
use of com.kymjs.rxvolley.http.URLHttpResponse in project yoo_home_Android by culturer.
the class OkHttpStack method responseFromConnection.
private URLHttpResponse responseFromConnection(Response okHttpResponse) throws IOException {
URLHttpResponse response = new URLHttpResponse();
// contentStream
int responseCode = okHttpResponse.code();
if (responseCode == -1) {
throw new IOException("Could not retrieve response code from HttpUrlConnection.");
}
response.setResponseCode(responseCode);
response.setResponseMessage(okHttpResponse.message());
response.setContentStream(okHttpResponse.body().byteStream());
response.setContentLength(okHttpResponse.body().contentLength());
response.setContentEncoding(okHttpResponse.header("Content-Encoding"));
if (okHttpResponse.body().contentType() != null) {
response.setContentType(okHttpResponse.body().contentType().type());
}
// header
HashMap<String, String> headerMap = new HashMap<>();
Headers responseHeaders = okHttpResponse.headers();
for (int i = 0, len = responseHeaders.size(); i < len; i++) {
final String name = responseHeaders.name(i), value = responseHeaders.value(i);
if (name != null) {
headerMap.put(name, value);
}
}
response.setHeaders(headerMap);
return response;
}
use of com.kymjs.rxvolley.http.URLHttpResponse in project yoo_home_Android by culturer.
the class OkHttpStack method performRequest.
@Override
public URLHttpResponse performRequest(Request<?> request, ArrayList<HttpParamsEntry> additionalHeaders) throws IOException {
int timeoutMs = request.getTimeoutMs();
OkHttpClient client = mClient.newBuilder().readTimeout(timeoutMs, TimeUnit.MILLISECONDS).connectTimeout(timeoutMs, TimeUnit.MILLISECONDS).writeTimeout(timeoutMs, TimeUnit.MILLISECONDS).build();
okhttp3.Request.Builder okHttpRequestBuilder = new okhttp3.Request.Builder();
okHttpRequestBuilder.url(request.getUrl());
for (final HttpParamsEntry entry : request.getHeaders()) {
okHttpRequestBuilder.addHeader(entry.k, entry.v);
}
for (final HttpParamsEntry entry : additionalHeaders) {
okHttpRequestBuilder.addHeader(entry.k, entry.v);
}
setConnectionParametersForRequest(okHttpRequestBuilder, request);
okhttp3.Request okHttpRequest = okHttpRequestBuilder.build();
Call okHttpCall = client.newCall(okHttpRequest);
Response okHttpResponse = okHttpCall.execute();
return responseFromConnection(okHttpResponse);
}
Aggregations