Skip to content

Commit

Permalink
Guard aggainst empty list.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cezary Krzyżanowski committed Feb 5, 2013
1 parent 6625620 commit 6c16cc8
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions Core/HTTPConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -2388,7 +2388,9 @@ - (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag
if (tag == HTTP_PARTIAL_RESPONSE_BODY)
{
// Update the amount of data we have in asyncSocket's write queue
[responseDataSizes removeObjectAtIndex:0];
if ([responseDataSizes count] > 0) {
[responseDataSizes removeObjectAtIndex:0];
}

// We only wrote a part of the response - there may be more
[self continueSendingStandardResponseBody];
Expand All @@ -2397,8 +2399,9 @@ - (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag
{
// Update the amount of data we have in asyncSocket's write queue.
// This will allow asynchronous responses to continue sending more data.
[responseDataSizes removeObjectAtIndex:0];

if ([responseDataSizes count] > 0) {
[responseDataSizes removeObjectAtIndex:0];
}
// Don't continue sending the response yet.
// The chunked footer that was sent after the body will tell us if we have more data to send.
}
Expand All @@ -2410,16 +2413,18 @@ - (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag
else if (tag == HTTP_PARTIAL_RANGE_RESPONSE_BODY)
{
// Update the amount of data we have in asyncSocket's write queue
[responseDataSizes removeObjectAtIndex:0];

if ([responseDataSizes count] > 0) {
[responseDataSizes removeObjectAtIndex:0];
}
// We only wrote a part of the range - there may be more
[self continueSendingSingleRangeResponseBody];
}
else if (tag == HTTP_PARTIAL_RANGES_RESPONSE_BODY)
{
// Update the amount of data we have in asyncSocket's write queue
[responseDataSizes removeObjectAtIndex:0];

if ([responseDataSizes count] > 0) {
[responseDataSizes removeObjectAtIndex:0];
}
// We only wrote part of the range - there may be more, or there may be more ranges
[self continueSendingMultiRangeResponseBody];
}
Expand Down

0 comments on commit 6c16cc8

Please sign in to comment.