use of com.taobao.weex.devtools.inspector.network.DefaultResponseHandler in project WeexErosFramework by bmfe.
the class WeexOkhttp3Interceptor method intercept.
@Override
public Response intercept(Chain chain) throws IOException {
String requestId = String.valueOf(mNextRequestId.getAndIncrement());
Request request = chain.request();
mEventReporter = NetworkEventReporterManager.get();
RequestBodyHelper requestBodyHelper = null;
if (mEventReporter != null) {
requestBodyHelper = new RequestBodyHelper(mEventReporter, requestId);
OkHttpInspectorRequest inspectorRequest = new OkHttpInspectorRequest(requestId, request, requestBodyHelper);
mEventReporter.requestWillBeSent(inspectorRequest);
}
Response response;
try {
response = chain.proceed(request);
} catch (IOException e) {
if (mEventReporter != null) {
mEventReporter.httpExchangeFailed(requestId, e.toString());
}
throw e;
}
if (mEventReporter != null) {
if (requestBodyHelper.hasBody()) {
requestBodyHelper.reportDataSent();
}
Connection connection = chain.connection();
mEventReporter.responseHeadersReceived(new OkHttpInspectorResponse(requestId, request, response));
ResponseBody body = response.body();
MediaType contentType = null;
InputStream responseStream = null;
if (body != null) {
contentType = body.contentType();
responseStream = body.byteStream();
}
responseStream = mEventReporter.interpretResponseStream(requestId, contentType != null ? contentType.toString() : null, response.header("Content-Encoding"), responseStream, new DefaultResponseHandler(mEventReporter, requestId));
if (responseStream != null) {
response = response.newBuilder().body(new ForwardingResponseBody(body, responseStream)).build();
}
}
return response;
}
use of com.taobao.weex.devtools.inspector.network.DefaultResponseHandler in project WeexErosFramework by bmfe.
the class WeexOkhttp3Interceptor method intercept.
@Override
public Response intercept(Chain chain) throws IOException {
String requestId = String.valueOf(mNextRequestId.getAndIncrement());
Request request = chain.request();
mEventReporter = NetworkEventReporterManager.get();
RequestBodyHelper requestBodyHelper = null;
if (mEventReporter != null) {
requestBodyHelper = new RequestBodyHelper(mEventReporter, requestId);
OkHttpInspectorRequest inspectorRequest = new OkHttpInspectorRequest(requestId, request, requestBodyHelper);
mEventReporter.requestWillBeSent(inspectorRequest);
}
Response response;
try {
response = chain.proceed(request);
} catch (IOException e) {
if (mEventReporter != null) {
mEventReporter.httpExchangeFailed(requestId, e.toString());
}
throw e;
}
if (mEventReporter != null) {
if (requestBodyHelper.hasBody()) {
requestBodyHelper.reportDataSent();
}
Connection connection = chain.connection();
mEventReporter.responseHeadersReceived(new OkHttpInspectorResponse(requestId, request, response));
ResponseBody body = response.body();
MediaType contentType = null;
InputStream responseStream = null;
if (body != null) {
contentType = body.contentType();
responseStream = body.byteStream();
}
responseStream = mEventReporter.interpretResponseStream(requestId, contentType != null ? contentType.toString() : null, response.header("Content-Encoding"), responseStream, new DefaultResponseHandler(mEventReporter, requestId));
if (responseStream != null) {
response = response.newBuilder().body(new ForwardingResponseBody(body, responseStream)).build();
}
}
return response;
}
Aggregations