mirror of
https://github.com/status-im/react-native.git
synced 2025-01-28 02:04:55 +00:00
Revert PR #17312 due to buck failures in continuous integration tests
Summary: Circle is currently failing on the `android` step due to a dependency issue introduced by the aforementioned PR. I am currently waiting for an internal diff to be reviewed which will restore this PR alongside the necessary dependency. Closes https://github.com/facebook/react-native/pull/17902 Differential Revision: D6937173 Pulled By: hramos fbshipit-source-id: f732a397521cc5df36f503e618318ef6d69aeaa6
This commit is contained in:
parent
47fe52380a
commit
2f02dd4c8c
@ -451,6 +451,12 @@ jobs:
|
|||||||
|
|
||||||
# Keep configuring Android dependencies while AVD boots up
|
# Keep configuring Android dependencies while AVD boots up
|
||||||
|
|
||||||
|
# Install Android NDK
|
||||||
|
- run: *create-ndk-directory
|
||||||
|
- restore-cache: *restore-cache-ndk
|
||||||
|
- run: *install-ndk
|
||||||
|
- save-cache: *save-cache-ndk
|
||||||
|
|
||||||
# Fetch dependencies using BUCK
|
# Fetch dependencies using BUCK
|
||||||
- restore-cache: *restore-cache-buck
|
- restore-cache: *restore-cache-buck
|
||||||
- run: *install-buck
|
- run: *install-buck
|
||||||
@ -463,12 +469,6 @@ jobs:
|
|||||||
- run: buck fetch ReactAndroid/src/androidTest/...
|
- run: buck fetch ReactAndroid/src/androidTest/...
|
||||||
- run: ./gradlew :ReactAndroid:downloadBoost :ReactAndroid:downloadDoubleConversion :ReactAndroid:downloadFolly :ReactAndroid:downloadGlog :ReactAndroid:downloadJSCHeaders
|
- run: ./gradlew :ReactAndroid:downloadBoost :ReactAndroid:downloadDoubleConversion :ReactAndroid:downloadFolly :ReactAndroid:downloadGlog :ReactAndroid:downloadJSCHeaders
|
||||||
|
|
||||||
# Install Android NDK
|
|
||||||
- run: *create-ndk-directory
|
|
||||||
- restore-cache: *restore-cache-ndk
|
|
||||||
- run: *install-ndk
|
|
||||||
- save-cache: *save-cache-ndk
|
|
||||||
|
|
||||||
# Build and compile
|
# Build and compile
|
||||||
- run: *build-android-app
|
- run: *build-android-app
|
||||||
- run: *compile-native-libs
|
- run: *compile-native-libs
|
||||||
|
@ -11,7 +11,6 @@ rn_android_library(
|
|||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"),
|
react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"),
|
||||||
react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/internal:internal"),
|
|
||||||
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
|
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
|
||||||
react_native_dep("third-party/java/jsr-305:jsr-305"),
|
react_native_dep("third-party/java/jsr-305:jsr-305"),
|
||||||
react_native_dep("third-party/java/okhttp:okhttp3"),
|
react_native_dep("third-party/java/okhttp:okhttp3"),
|
||||||
|
@ -343,11 +343,11 @@ public final class NetworkingModule extends ReactContextBaseJavaModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RequestBody requestBody;
|
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
requestBody = RequestBodyUtil.getEmptyBody(method);
|
requestBuilder.method(method, RequestBodyUtil.getEmptyBody(method));
|
||||||
} else if (handler != null) {
|
} else if (handler != null) {
|
||||||
requestBody = handler.toRequestBody(data, contentType);
|
RequestBody requestBody = handler.toRequestBody(data, contentType);
|
||||||
|
requestBuilder.method(method, requestBody);
|
||||||
} else if (data.hasKey(REQUEST_BODY_KEY_STRING)) {
|
} else if (data.hasKey(REQUEST_BODY_KEY_STRING)) {
|
||||||
if (contentType == null) {
|
if (contentType == null) {
|
||||||
ResponseUtil.onRequestError(
|
ResponseUtil.onRequestError(
|
||||||
@ -360,13 +360,14 @@ public final class NetworkingModule extends ReactContextBaseJavaModule {
|
|||||||
String body = data.getString(REQUEST_BODY_KEY_STRING);
|
String body = data.getString(REQUEST_BODY_KEY_STRING);
|
||||||
MediaType contentMediaType = MediaType.parse(contentType);
|
MediaType contentMediaType = MediaType.parse(contentType);
|
||||||
if (RequestBodyUtil.isGzipEncoding(contentEncoding)) {
|
if (RequestBodyUtil.isGzipEncoding(contentEncoding)) {
|
||||||
requestBody = RequestBodyUtil.createGzip(contentMediaType, body);
|
RequestBody requestBody = RequestBodyUtil.createGzip(contentMediaType, body);
|
||||||
if (requestBody == null) {
|
if (requestBody == null) {
|
||||||
ResponseUtil.onRequestError(eventEmitter, requestId, "Failed to gzip request body", null);
|
ResponseUtil.onRequestError(eventEmitter, requestId, "Failed to gzip request body", null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
requestBuilder.method(method, requestBody);
|
||||||
} else {
|
} else {
|
||||||
requestBody = RequestBody.create(contentMediaType, body);
|
requestBuilder.method(method, RequestBody.create(contentMediaType, body));
|
||||||
}
|
}
|
||||||
} else if (data.hasKey(REQUEST_BODY_KEY_BASE64)) {
|
} else if (data.hasKey(REQUEST_BODY_KEY_BASE64)) {
|
||||||
if (contentType == null) {
|
if (contentType == null) {
|
||||||
@ -379,7 +380,9 @@ public final class NetworkingModule extends ReactContextBaseJavaModule {
|
|||||||
}
|
}
|
||||||
String base64String = data.getString(REQUEST_BODY_KEY_BASE64);
|
String base64String = data.getString(REQUEST_BODY_KEY_BASE64);
|
||||||
MediaType contentMediaType = MediaType.parse(contentType);
|
MediaType contentMediaType = MediaType.parse(contentType);
|
||||||
requestBody = RequestBody.create(contentMediaType, ByteString.decodeBase64(base64String));
|
requestBuilder.method(
|
||||||
|
method,
|
||||||
|
RequestBody.create(contentMediaType, ByteString.decodeBase64(base64String)));
|
||||||
} else if (data.hasKey(REQUEST_BODY_KEY_URI)) {
|
} else if (data.hasKey(REQUEST_BODY_KEY_URI)) {
|
||||||
if (contentType == null) {
|
if (contentType == null) {
|
||||||
ResponseUtil.onRequestError(
|
ResponseUtil.onRequestError(
|
||||||
@ -400,7 +403,9 @@ public final class NetworkingModule extends ReactContextBaseJavaModule {
|
|||||||
null);
|
null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
requestBody = RequestBodyUtil.create(MediaType.parse(contentType), fileInputStream);
|
requestBuilder.method(
|
||||||
|
method,
|
||||||
|
RequestBodyUtil.create(MediaType.parse(contentType), fileInputStream));
|
||||||
} else if (data.hasKey(REQUEST_BODY_KEY_FORMDATA)) {
|
} else if (data.hasKey(REQUEST_BODY_KEY_FORMDATA)) {
|
||||||
if (contentType == null) {
|
if (contentType == null) {
|
||||||
contentType = "multipart/form-data";
|
contentType = "multipart/form-data";
|
||||||
@ -411,16 +416,28 @@ public final class NetworkingModule extends ReactContextBaseJavaModule {
|
|||||||
if (multipartBuilder == null) {
|
if (multipartBuilder == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
requestBody = multipartBuilder.build();
|
|
||||||
|
requestBuilder.method(
|
||||||
|
method,
|
||||||
|
RequestBodyUtil.createProgressRequest(
|
||||||
|
multipartBuilder.build(),
|
||||||
|
new ProgressListener() {
|
||||||
|
long last = System.nanoTime();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProgress(long bytesWritten, long contentLength, boolean done) {
|
||||||
|
long now = System.nanoTime();
|
||||||
|
if (done || shouldDispatch(now, last)) {
|
||||||
|
ResponseUtil.onDataSend(eventEmitter, requestId, bytesWritten, contentLength);
|
||||||
|
last = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
} else {
|
} else {
|
||||||
// Nothing in data payload, at least nothing we could understand anyway.
|
// Nothing in data payload, at least nothing we could understand anyway.
|
||||||
requestBody = RequestBodyUtil.getEmptyBody(method);
|
requestBuilder.method(method, RequestBodyUtil.getEmptyBody(method));
|
||||||
}
|
}
|
||||||
|
|
||||||
requestBuilder.method(
|
|
||||||
method,
|
|
||||||
wrapRequestBodyWithProgressEmitter(requestBody, eventEmitter, requestId));
|
|
||||||
|
|
||||||
addRequest(requestId);
|
addRequest(requestId);
|
||||||
client.newCall(requestBuilder.build()).enqueue(
|
client.newCall(requestBuilder.build()).enqueue(
|
||||||
new Callback() {
|
new Callback() {
|
||||||
@ -498,29 +515,6 @@ public final class NetworkingModule extends ReactContextBaseJavaModule {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private RequestBody wrapRequestBodyWithProgressEmitter(
|
|
||||||
final RequestBody requestBody,
|
|
||||||
final RCTDeviceEventEmitter eventEmitter,
|
|
||||||
final int requestId) {
|
|
||||||
if(requestBody == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return RequestBodyUtil.createProgressRequest(
|
|
||||||
requestBody,
|
|
||||||
new ProgressListener() {
|
|
||||||
long last = System.nanoTime();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onProgress(long bytesWritten, long contentLength, boolean done) {
|
|
||||||
long now = System.nanoTime();
|
|
||||||
if (done || shouldDispatch(now, last)) {
|
|
||||||
ResponseUtil.onDataSend(eventEmitter, requestId, bytesWritten, contentLength);
|
|
||||||
last = now;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void readWithProgress(
|
private void readWithProgress(
|
||||||
RCTDeviceEventEmitter eventEmitter,
|
RCTDeviceEventEmitter eventEmitter,
|
||||||
int requestId,
|
int requestId,
|
||||||
|
@ -9,75 +9,60 @@
|
|||||||
|
|
||||||
package com.facebook.react.modules.network;
|
package com.facebook.react.modules.network;
|
||||||
|
|
||||||
import com.facebook.common.internal.CountingOutputStream;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import okhttp3.MediaType;
|
import okhttp3.MediaType;
|
||||||
import okhttp3.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
import okio.BufferedSink;
|
import okio.BufferedSink;
|
||||||
import okio.Okio;
|
import okio.Buffer;
|
||||||
import okio.Sink;
|
import okio.Sink;
|
||||||
|
import okio.ForwardingSink;
|
||||||
|
import okio.Okio;
|
||||||
|
|
||||||
public class ProgressRequestBody extends RequestBody {
|
public class ProgressRequestBody extends RequestBody {
|
||||||
|
|
||||||
private final RequestBody mRequestBody;
|
private final RequestBody mRequestBody;
|
||||||
private final ProgressListener mProgressListener;
|
private final ProgressListener mProgressListener;
|
||||||
private BufferedSink mBufferedSink;
|
private BufferedSink mBufferedSink;
|
||||||
private long mContentLength = 0L;
|
|
||||||
|
|
||||||
public ProgressRequestBody(RequestBody requestBody, ProgressListener progressListener) {
|
public ProgressRequestBody(RequestBody requestBody, ProgressListener progressListener) {
|
||||||
mRequestBody = requestBody;
|
mRequestBody = requestBody;
|
||||||
mProgressListener = progressListener;
|
mProgressListener = progressListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MediaType contentType() {
|
public MediaType contentType() {
|
||||||
return mRequestBody.contentType();
|
return mRequestBody.contentType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long contentLength() throws IOException {
|
public long contentLength() throws IOException {
|
||||||
if (mContentLength == 0) {
|
return mRequestBody.contentLength();
|
||||||
mContentLength = mRequestBody.contentLength();
|
|
||||||
}
|
|
||||||
return mContentLength;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(BufferedSink sink) throws IOException {
|
public void writeTo(BufferedSink sink) throws IOException {
|
||||||
if (mBufferedSink == null) {
|
if (mBufferedSink == null) {
|
||||||
mBufferedSink = Okio.buffer(outputStreamSink(sink));
|
mBufferedSink = Okio.buffer(sink(sink));
|
||||||
}
|
}
|
||||||
|
mRequestBody.writeTo(mBufferedSink);
|
||||||
// contentLength changes for input streams, since we're using inputStream.available(),
|
mBufferedSink.flush();
|
||||||
// so get the length before writing to the sink
|
|
||||||
contentLength();
|
|
||||||
|
|
||||||
mRequestBody.writeTo(mBufferedSink);
|
|
||||||
mBufferedSink.flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Sink outputStreamSink(BufferedSink sink) {
|
private Sink sink(Sink sink) {
|
||||||
return Okio.sink(new CountingOutputStream(sink.outputStream()) {
|
return new ForwardingSink(sink) {
|
||||||
@Override
|
long bytesWritten = 0L;
|
||||||
public void write(byte[] data, int offset, int byteCount) throws IOException {
|
long contentLength = 0L;
|
||||||
super.write(data, offset, byteCount);
|
|
||||||
sendProgressUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(int data) throws IOException {
|
public void write(Buffer source, long byteCount) throws IOException {
|
||||||
super.write(data);
|
super.write(source, byteCount);
|
||||||
sendProgressUpdate();
|
if (contentLength == 0) {
|
||||||
}
|
contentLength = contentLength();
|
||||||
|
}
|
||||||
private void sendProgressUpdate() throws IOException {
|
bytesWritten += byteCount;
|
||||||
long bytesWritten = getCount();
|
mProgressListener.onProgress(
|
||||||
long contentLength = contentLength();
|
bytesWritten, contentLength, bytesWritten == contentLength);
|
||||||
mProgressListener.onProgress(
|
}
|
||||||
bytesWritten, contentLength, bytesWritten == contentLength);
|
};
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -200,10 +200,6 @@ public class NetworkingModuleTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccessfulPostRequest() throws Exception {
|
public void testSuccessfulPostRequest() throws Exception {
|
||||||
RCTDeviceEventEmitter emitter = mock(RCTDeviceEventEmitter.class);
|
|
||||||
ReactApplicationContext context = mock(ReactApplicationContext.class);
|
|
||||||
when(context.getJSModule(any(Class.class))).thenReturn(emitter);
|
|
||||||
|
|
||||||
OkHttpClient httpClient = mock(OkHttpClient.class);
|
OkHttpClient httpClient = mock(OkHttpClient.class);
|
||||||
when(httpClient.newCall(any(Request.class))).thenAnswer(new Answer<Object>() {
|
when(httpClient.newCall(any(Request.class))).thenAnswer(new Answer<Object>() {
|
||||||
@Override
|
@Override
|
||||||
@ -215,13 +211,12 @@ public class NetworkingModuleTest {
|
|||||||
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
|
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
|
||||||
when(clientBuilder.build()).thenReturn(httpClient);
|
when(clientBuilder.build()).thenReturn(httpClient);
|
||||||
when(httpClient.newBuilder()).thenReturn(clientBuilder);
|
when(httpClient.newBuilder()).thenReturn(clientBuilder);
|
||||||
NetworkingModule networkingModule = new NetworkingModule(context, "", httpClient);
|
NetworkingModule networkingModule =
|
||||||
|
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
|
||||||
|
|
||||||
JavaOnlyMap body = new JavaOnlyMap();
|
JavaOnlyMap body = new JavaOnlyMap();
|
||||||
body.putString("string", "This is request body");
|
body.putString("string", "This is request body");
|
||||||
|
|
||||||
mockEvents();
|
|
||||||
|
|
||||||
networkingModule.sendRequest(
|
networkingModule.sendRequest(
|
||||||
"POST",
|
"POST",
|
||||||
"http://somedomain/bar",
|
"http://somedomain/bar",
|
||||||
@ -635,4 +630,4 @@ public class NetworkingModuleTest {
|
|||||||
assertThat(requestIdArguments.getAllValues().contains(idx + 1)).isTrue();
|
assertThat(requestIdArguments.getAllValues().contains(idx + 1)).isTrue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user