Toggle navigation
Toggle navigation
This project
Loading...
Sign in
iOS
/
asi-http-request
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Ben Copsey
2009-11-14 14:55:26 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c2ecd61bc6b0d9f662ba5cee8686f2d8e1ac6ccc
c2ecd61b
1 parent
2d4cbd0c
Fix download progress when no content length header comes in
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
44 deletions
Classes/ASIHTTPRequest.m
Classes/Tests/ASINetworkQueueTests.h
Classes/Tests/ASINetworkQueueTests.m
iPhone Sample/Info.plist
iPhone.xcodeproj/project.pbxproj
Classes/ASIHTTPRequest.m
View file @
c2ecd61
...
...
@@ -480,9 +480,7 @@ static BOOL isiPhoneOS2;
[
pool
release
];
return
;
}
//If this is a HEAD request generated by an ASINetworkQueue, we need to let the main request generate its headers first so we can use them
if
([
self
mainRequest
])
{
[[
self
mainRequest
]
buildRequestHeaders
];
...
...
@@ -1146,7 +1144,7 @@ static BOOL isiPhoneOS2;
// We won't update download progress until we've examined the headers, since we might need to authenticate
if
(
responseHeaders
)
{
if
(
[
self
responseHeaders
]
&&
([
self
contentLength
]
||
[
self
complete
])
)
{
unsigned
long
long
bytesReadSoFar
=
totalBytesRead
+
partialDownloadSize
;
...
...
@@ -1157,7 +1155,7 @@ static BOOL isiPhoneOS2;
NSAutoreleasePool
*
thePool
=
[[
NSAutoreleasePool
alloc
]
init
];
unsigned
long
long
value
=
0
;
if
([
self
showAccurateProgress
])
{
if
([
self
showAccurateProgress
]
&&
[
self
contentLength
]
)
{
value
=
bytesReadSoFar
-
[
self
lastBytesRead
];
}
else
{
value
=
1
;
...
...
@@ -1176,23 +1174,17 @@ static BOOL isiPhoneOS2;
}
if
(
downloadProgressDelegate
)
{
if
(
contentLength
>
0
)
{
double
progress
;
double
progress
=
1
.
0
;
if
([
self
contentLength
])
{
//Workaround for an issue with converting a long to a double on iPhone OS 2.2.1 with a base SDK >= 3.0
if
([
ASIHTTPRequest
isiPhoneOS2
])
{
progress
=
[[
NSNumber
numberWithUnsignedLongLong
:
bytesReadSoFar
/
(
contentLength
+
partialDownloadSize
)]
doubleValue
];
}
else
{
progress
=
(
double
)(
1
.
0
*
bytesReadSoFar
/
(
contentLength
+
partialDownloadSize
));
}
[
self
setUpdatedProgress
:
YES
];
[
ASIHTTPRequest
setProgress
:
progress
forProgressIndicator
:
downloadProgressDelegate
];
// Request has finished, but we've never updated the progress
// This is either an error, or we got no Content-Length header
}
else
if
([
self
complete
]
&&
!
[
self
updatedProgress
])
{
[
self
setUpdatedProgress
:
YES
];
[
ASIHTTPRequest
setProgress
:
1
.
0
forProgressIndicator
:
downloadProgressDelegate
];
}
[
self
setUpdatedProgress
:
YES
];
[
ASIHTTPRequest
setProgress
:
progress
forProgressIndicator
:
downloadProgressDelegate
];
}
[
self
setLastBytesRead
:
bytesReadSoFar
];
...
...
@@ -1367,6 +1359,8 @@ static BOOL isiPhoneOS2;
if
([
self
showAccurateProgress
]
&&
[
self
shouldResetProgressIndicators
])
{
[
self
resetDownloadProgress
:[
self
contentLength
]
+
[
self
partialDownloadSize
]];
}
}
else
if
([
self
showAccurateProgress
]
&&
[
self
shouldResetProgressIndicators
])
{
[
self
resetDownloadProgress
:
1
];
}
// Handle response text encoding
...
...
Classes/Tests/ASINetworkQueueTests.h
View file @
c2ecd61
...
...
@@ -42,7 +42,7 @@ IMPORTANT
-
(
void
)
testFailure
;
-
(
void
)
testFailureCancelsOtherRequests
;
-
(
void
)
testProgress
;
-
(
void
)
test
Download
Progress
;
-
(
void
)
testUploadProgress
;
-
(
void
)
testProgressWithAuthentication
;
-
(
void
)
testWithNoListener
;
...
...
Classes/Tests/ASINetworkQueueTests.m
View file @
c2ecd61
...
...
@@ -54,7 +54,7 @@ IMPORTANT
-
(
void
)
testProgress
-
(
void
)
test
Download
Progress
{
complete
=
NO
;
progress
=
0
;
...
...
@@ -66,27 +66,33 @@ IMPORTANT
[
networkQueue
setQueueDidFinishSelector
:
@selector
(
queueFinished
:)];
NSURL
*
url
;
url
=
[[[
NSURL
alloc
]
initWithString
:
@"http://allseeing-i.com/i/logo.png"
]
autorelease
];
ASIHTTPRequest
*
request1
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
networkQueue
addOperation
:
request1
];
url
=
[[[
NSURL
alloc
]
initWithString
:
@"http://allseeing-i.com/i/trailsnetwork.png"
]
autorelease
];
ASIHTTPRequest
*
request2
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
networkQueue
addOperation
:
request2
];
url
=
[[[
NSURL
alloc
]
initWithString
:
@"http://allseeing-i.com/sharedspace20.png"
]
autorelease
];
ASIHTTPRequest
*
request3
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
networkQueue
addOperation
:
request3
];
[
networkQueue
go
];
while
(
!
complete
)
{
[[
NSRunLoop
currentRunLoop
]
runUntilDate
:[
NSDate
dateWithTimeIntervalSinceNow
:
0
.
25
]];
}
[[
NSRunLoop
currentRunLoop
]
runUntilDate
:[
NSDate
dateWithTimeIntervalSinceNow
:
1
]];
// url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com"] autorelease];
// ASIHTTPRequest *request1 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
// [networkQueue addOperation:request1];
//
// url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com"] autorelease];
// ASIHTTPRequest *request2 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
// [networkQueue addOperation:request2];
//
// url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com"] autorelease];
// ASIHTTPRequest *request3 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
// [networkQueue addOperation:request3];
//
// url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com"] autorelease];
// ASIHTTPRequest *request4 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
// [networkQueue addOperation:request4];
//
// [networkQueue go];
//
// while (!complete) {
// [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
// }
//
// [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
BOOL
success
=
(
progress
>
0
.
95
);
GHAssertTrue
(
success
,
@"Failed to increment progress properly"
);
// GHAssertTrue(success,@"Failed to increment progress properly");
//
//Now test again with accurate progress
complete
=
NO
;
...
...
@@ -94,21 +100,31 @@ IMPORTANT
[
networkQueue
cancelAllOperations
];
[
networkQueue
setShowAccurateProgress
:
YES
];
url
=
[[[
NSURL
alloc
]
initWithString
:
@"http://allseeing-i.com/i/logo.png"
]
autorelease
];
request1
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
url
=
[[[
NSURL
alloc
]
initWithString
:
@"http://allseeing-i.com"
]
autorelease
];
ASIHTTPRequest
*
request1
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
request1
setAllowCompressedResponse
:
NO
];
[
networkQueue
addOperation
:
request1
];
url
=
[[[
NSURL
alloc
]
initWithString
:
@"http://allseeing-i.com/i/trailsnetwork.png"
]
autorelease
];
request2
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
url
=
[[[
NSURL
alloc
]
initWithString
:
@"http://allseeing-i.com"
]
autorelease
];
ASIHTTPRequest
*
request2
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
request2
setAllowCompressedResponse
:
NO
];
[
networkQueue
addOperation
:
request2
];
url
=
[[[
NSURL
alloc
]
initWithString
:
@"http://allseeing-i.com/sharedspace20.png"
]
autorelease
];
request3
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
url
=
[[[
NSURL
alloc
]
initWithString
:
@"http://allseeing-i.com"
]
autorelease
];
ASIHTTPRequest
*
request3
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
request3
setAllowCompressedResponse
:
NO
];
[
networkQueue
addOperation
:
request3
];
url
=
[[[
NSURL
alloc
]
initWithString
:
@"http://allseeing-i.com"
]
autorelease
];
ASIHTTPRequest
*
request4
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
request4
setAllowCompressedResponse
:
NO
];
[
networkQueue
addOperation
:
request4
];
[
networkQueue
go
];
[
networkQueue
waitUntilAllOperationsAreFinished
];
while
(
!
complete
)
{
[[
NSRunLoop
currentRunLoop
]
runUntilDate
:[
NSDate
dateWithTimeIntervalSinceNow
:
0
.
25
]];
}
// Progress maths are inexact for queues
success
=
(
progress
>
0
.
95
);
...
...
@@ -186,6 +202,11 @@ IMPORTANT
-
(
void
)
setProgress
:
(
float
)
newProgress
{
if
(
newProgress
<
progress
)
{
GHFail
(
@"Progress went backwards!"
);
}
NSLog
(
@"%f"
,
newProgress
);
progress
=
newProgress
;
}
...
...
iPhone Sample/Info.plist
View file @
c2ecd61
...
...
@@ -9,7 +9,7 @@
<key>
CFBundleIconFile
</key>
<string>
iphone-icon.png
</string>
<key>
CFBundleIdentifier
</key>
<string>
com.
yaddy.yadda.blah
</string>
<string>
com.
allseeinginteractive.trailsnetwork.foo
</string>
<key>
CFBundleInfoDictionaryVersion
</key>
<string>
6.0
</string>
<key>
CFBundlePackageType
</key>
...
...
iPhone.xcodeproj/project.pbxproj
View file @
c2ecd61
This diff was suppressed by a .gitattributes entry.
Please
register
or
login
to post a comment