Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed a race condition in the HTTP listener

Sometimes it would never send the body of a response or close the socket.
I saw this happen with error responses like 404s; not sure it it would happen otherwise.
  • Loading branch information...
commit 40ae2aee86965b40e9fb9055ebbb3a1fb444c289 1 parent ee1c751
@snej snej authored
Showing with 3 additions and 2 deletions.
  1. +3 −2 Listener/TDHTTPResponse.m
View
5 Listener/TDHTTPResponse.m
@@ -169,6 +169,7 @@ - (NSData*) readDataOfLength: (NSUInteger)length {
- (BOOL) isDone {
+ LogTo(TDListenerVerbose, @"%@ answers isDone=%d", self, _finished);
return _finished;
}
@@ -187,7 +188,7 @@ - (void) onFinished {
_router.onDataAvailable = nil;
_router.onFinished = nil;
- if (_chunked) {
+ if (_chunked && _offset > 0) {
[_connection responseHasAvailableData: self];
} else {
// Response finished immediately, before the connection asked for any data, so we're free
@@ -205,9 +206,9 @@ - (void) onFinished {
}
NSString* responseStr = [NSString stringWithFormat: @"{\"status\": %i, \"error\":\"%@\"}\n",
status, errorMsg];
+ [_response.headers setObject: @"text/plain; encoding=UTF-8" forKey: @"Content-Type"];
[self onDataAvailable: [responseStr dataUsingEncoding: NSUTF8StringEncoding]
finished: NO];
- [_response.headers setObject: @"text/plain; encoding=UTF-8" forKey: @"Content-Type"];
} else {
#if DEBUG
BOOL pretty = YES;
Please sign in to comment.
Something went wrong with that request. Please try again.