Skip to content
This repository
Browse code

Fix for TDMultipartDownloader in case NSURLConnection gets two responses

It's possible in rare cases for the didReceiveResponse: delegate method to be called twice.
Handle this correctly by creating a new _reader within that call.
Thanks to @kjots, @chaisehocking, @drekka for tracking this down!
Speculatively fixes #236.
  • Loading branch information...
commit 5eda8aff42a1f360b48852cf0d5e34316f72edf4 1 parent 813f4ac
Jens Alfke authored
1  Source/TDMultipartDownloader.h
@@ -15,6 +15,7 @@
15 15
 @interface TDMultipartDownloader : TDRemoteRequest
16 16
 {
17 17
     @private
  18
+    TD_Database* _db;
18 19
     TDMultipartDocumentReader* _reader;
19 20
 }
20 21
 
3  Source/TDMultipartDownloader.m
@@ -35,7 +35,7 @@ - (id) initWithURL: (NSURL*)url
35 35
                   requestHeaders: requestHeaders
36 36
                     onCompletion: onCompletion];
37 37
     if (self) {
38  
-        _reader = [[TDMultipartDocumentReader alloc] initWithDatabase: database];
  38
+        _db = database;
39 39
     }
40 40
     return self;
41 41
 }
@@ -63,6 +63,7 @@ - (NSDictionary*) document {
63 63
 
64 64
 
65 65
 - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
  66
+    _reader = [[TDMultipartDocumentReader alloc] initWithDatabase: _db];
66 67
     TDStatus status = (TDStatus) ((NSHTTPURLResponse*)response).statusCode;
67 68
     if (status < 300) {
68 69
         // Check the content type to see whether it's a multipart response:

0 notes on commit 5eda8af

Please sign in to comment.
Something went wrong with that request. Please try again.