File tree 1 file changed +6
-6
lines changed
ReactAndroid/src/main/java/com/facebook/react/modules/network
1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,6 @@ public class ProgressRequestBody extends RequestBody {
19
19
20
20
private final RequestBody mRequestBody ;
21
21
private final ProgressListener mProgressListener ;
22
- private BufferedSink mBufferedSink ;
23
22
private long mContentLength = 0L ;
24
23
25
24
public ProgressRequestBody (RequestBody requestBody , ProgressListener progressListener ) {
@@ -42,16 +41,17 @@ public long contentLength() throws IOException {
42
41
43
42
@ Override
44
43
public void writeTo (BufferedSink sink ) throws IOException {
45
- if (mBufferedSink == null ) {
46
- mBufferedSink = Okio .buffer (outputStreamSink (sink ));
47
- }
44
+ // In 99% of cases, this method is called strictly once.
45
+ // The only case when it is called more than once is internal okhttp upload re-try.
46
+ // We need to re-create CountingOutputStream in this case as progress should be re-evaluated.
47
+ BufferedSink sinkWrapper = Okio .buffer (outputStreamSink (sink ));
48
48
49
49
// contentLength changes for input streams, since we're using inputStream.available(),
50
50
// so get the length before writing to the sink
51
51
contentLength ();
52
52
53
- mRequestBody .writeTo (mBufferedSink );
54
- mBufferedSink .flush ();
53
+ mRequestBody .writeTo (sinkWrapper );
54
+ sinkWrapper .flush ();
55
55
}
56
56
57
57
private Sink outputStreamSink (BufferedSink sink ) {
You can’t perform that action at this time.
0 commit comments