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
2010-10-18 16:37:05 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8a17855842240f798e92b12bf73297a3afc0635a
8a178558
1 parent
0f5c91a5
Fixes, start moving block calling onto main thread
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
120 additions
and
43 deletions
Classes/ASIHTTPRequest.m
Mac.xcodeproj/project.pbxproj
iPhone.xcodeproj/project.pbxproj
Classes/ASIHTTPRequest.m
View file @
8a17855
...
...
@@ -24,7 +24,7 @@
#import "ASIDataCompressor.h"
// Automatically set on build
NSString
*
ASIHTTPRequestVersion
=
@"v1.7-11
5
2010-10-18"
;
NSString
*
ASIHTTPRequestVersion
=
@"v1.7-11
9
2010-10-18"
;
NSString
*
const
NetworkRequestErrorDomain
=
@"ASIHTTPRequestErrorDomain"
;
...
...
@@ -150,8 +150,8 @@ static NSOperationQueue *sharedQueue = nil;
-
(
void
)
scheduleReadStream
;
-
(
void
)
unscheduleReadStream
;
-
(
BOOL
)
a
skDelegateForCredentials
;
-
(
BOOL
)
a
skDelegateForProxyCredentials
;
-
(
BOOL
)
willA
skDelegateForCredentials
;
-
(
BOOL
)
willA
skDelegateForProxyCredentials
;
+
(
void
)
measureBandwidthUsage
;
+
(
void
)
recordBandwidthUsage
;
-
(
void
)
startRequest
;
...
...
@@ -1577,12 +1577,22 @@ static NSOperationQueue *sharedQueue = nil;
#if NS_BLOCKS_AVAILABLE
if
(
bytesReceivedBlock
)
{
__block
ASIHTTPRequest
*
blockCopy
=
self
;
bytesReceivedBlock
(
blockCopy
,
bytesReadSoFar
,
blockCopy
->
contentLength
+
blockCopy
->
partialDownloadSize
);
bytesReceivedBlock
(
blockCopy
,
value
,
blockCopy
->
contentLength
+
blockCopy
->
partialDownloadSize
);
}
#endif
[
self
setLastBytesRead
:
bytesReadSoFar
];
}
#if NS_BLOCKS_AVAILABLE
-
(
void
)
callBytesReceivedBlockWithBytes
:
(
unsigned
long
long
)
bytes
ofTotal
:
(
unsigned
long
long
)
total
{
if
(
bytesReceivedBlock
)
{
__block
ASIHTTPRequest
*
blockCopy
=
self
;
bytesReceivedBlock
(
blockCopy
,
bytes
,
blockCopy
->
contentLength
+
blockCopy
->
partialDownloadSize
);
}
}
#endif
-
(
void
)
updateUploadProgress
{
...
...
@@ -1741,8 +1751,7 @@ static NSOperationQueue *sharedQueue = nil;
}
#pragma mark talking to delegates
#pragma mark talking to delegates / calling blocks
/* ALWAYS CALLED ON MAIN THREAD! */
-
(
void
)
requestStarted
...
...
@@ -1756,9 +1765,34 @@ static NSOperationQueue *sharedQueue = nil;
if
(
queue
&&
[
queue
respondsToSelector
:
@selector
(
requestStarted
:)])
{
[
queue
performSelector
:
@selector
(
requestStarted
:)
withObject
:
self
];
}
#if NS_BLOCKS_AVAILABLE
if
(
startedBlock
){
__block
ASIHTTPRequest
*
blockCopy
=
self
;
startedBlock
(
blockCopy
);
}
#endif
}
/* ALWAYS CALLED ON MAIN THREAD! */
-
(
void
)
requestRedirected
{
if
([
self
error
]
||
[
self
mainRequest
])
{
return
;
}
if
([[
self
delegate
]
respondsToSelector
:
@selector
(
requestRedirected
:)]){
[[
self
delegate
]
performSelector
:
@selector
(
requestRedirected
:)
withObject
:
self
];
}
#if NS_BLOCKS_AVAILABLE
if
(
requestRedirectedBlock
){
__block
ASIHTTPRequest
*
blockCopy
=
self
;
requestRedirectedBlock
(
blockCopy
);
}
#endif
}
/* ALWAYS CALLED ON MAIN THREAD! */
-
(
void
)
requestReceivedResponseHeaders
:
(
NSMutableDictionary
*
)
newResponseHeaders
{
if
([
self
error
]
||
[
self
mainRequest
])
{
...
...
@@ -2010,15 +2044,7 @@ static NSOperationQueue *sharedQueue = nil;
if
([
self
shouldRedirect
]
&&
[
responseHeaders
valueForKey
:
@"Location"
])
{
if
(([
self
responseStatusCode
]
>
300
&&
[
self
responseStatusCode
]
<
304
)
||
[
self
responseStatusCode
]
==
307
)
{
if
([[
self
delegate
]
respondsToSelector
:
@selector
(
requestRedirected
:)]){
[[
self
delegate
]
performSelectorOnMainThread
:
@selector
(
requestRedirected
:)
withObject
:
self
waitUntilDone
:
[
NSThread
isMainThread
]];
}
#if NS_BLOCKS_AVAILABLE
if
(
requestRedirectedBlock
){
__block
ASIHTTPRequest
*
blockCopy
=
self
;
requestRedirectedBlock
(
blockCopy
);
}
#endif
[
self
performSelectorOnMainThread
:
@selector
(
requestRedirected
)
withObject
:
nil
waitUntilDone
:
[
NSThread
isMainThread
]];
// By default, we redirect 301 and 302 response codes as GET requests
// According to RFC 2616 this is wrong, but this is what most browsers do, so it's probably what you're expecting to happen
...
...
@@ -2378,7 +2404,7 @@ static NSOperationQueue *sharedQueue = nil;
}
-
(
BOOL
)
a
skDelegateForProxyCredentials
-
(
BOOL
)
willA
skDelegateForProxyCredentials
{
// If we have a delegate, we'll see if it can handle proxyAuthenticationNeededForRequest:.
// Otherwise, we'll try the queue (if this request is part of one) and it will pass the message on to its own delegate
...
...
@@ -2386,20 +2412,91 @@ static NSOperationQueue *sharedQueue = nil;
if
(
!
authenticationDelegate
)
{
authenticationDelegate
=
[
self
queue
];
}
BOOL
delegateOrBlockWillHandleAuthentication
=
NO
;
if
([
authenticationDelegate
respondsToSelector
:
@selector
(
proxyAuthenticationNeededForRequest
:)])
{
[
authenticationDelegate
performSelectorOnMainThread
:
@selector
(
proxyAuthenticationNeededForRequest
:)
withObject
:
self
waitUntilDone
:
[
NSThread
isMainThread
]];
return
YES
;
delegateOrBlockWillHandleAuthentication
=
YES
;
}
#if NS_BLOCKS_AVAILABLE
if
(
proxyAuthenticationNeededBlock
){
delegateOrBlockWillHandleAuthentication
=
YES
;
}
#endif
if
(
delegateOrBlockWillHandleAuthentication
)
{
[
self
performSelectorOnMainThread
:
@selector
(
askDelegateForProxyCredentials
)
withObject
:
nil
waitUntilDone
:
NO
];
}
return
delegateOrBlockWillHandleAuthentication
;
}
/* ALWAYS CALLED ON MAIN THREAD! */
-
(
void
)
askDelegateForProxyCredentials
{
id
authenticationDelegate
=
[
self
delegate
];
if
(
!
authenticationDelegate
)
{
authenticationDelegate
=
[
self
queue
];
}
if
([
authenticationDelegate
respondsToSelector
:
@selector
(
proxyAuthenticationNeededForRequest
:)])
{
[
authenticationDelegate
performSelector
:
@selector
(
proxyAuthenticationNeededForRequest
:)
withObject
:
self
];
return
;
}
#if NS_BLOCKS_AVAILABLE
if
(
proxyAuthenticationNeededBlock
){
__block
ASIHTTPRequest
*
blockCopy
=
self
;
proxyAuthenticationNeededBlock
(
blockCopy
);
}
#endif
}
return
NO
;
-
(
BOOL
)
willAskDelegateForCredentials
{
// If we have a delegate, we'll see if it can handle proxyAuthenticationNeededForRequest:.
// Otherwise, we'll try the queue (if this request is part of one) and it will pass the message on to its own delegate
id
authenticationDelegate
=
[
self
delegate
];
if
(
!
authenticationDelegate
)
{
authenticationDelegate
=
[
self
queue
];
}
BOOL
delegateOrBlockWillHandleAuthentication
=
NO
;
if
([
authenticationDelegate
respondsToSelector
:
@selector
(
authenticationNeededForRequest
:)])
{
delegateOrBlockWillHandleAuthentication
=
YES
;
}
#if NS_BLOCKS_AVAILABLE
if
(
authenticationNeededBlock
)
{
delegateOrBlockWillHandleAuthentication
=
YES
;
}
#endif
if
(
delegateOrBlockWillHandleAuthentication
)
{
[
self
performSelectorOnMainThread
:
@selector
(
askDelegateForCredentials
)
withObject
:
nil
waitUntilDone
:
NO
];
}
return
delegateOrBlockWillHandleAuthentication
;
}
/* ALWAYS CALLED ON MAIN THREAD! */
-
(
void
)
askDelegateForCredentials
{
id
authenticationDelegate
=
[
self
delegate
];
if
(
!
authenticationDelegate
)
{
authenticationDelegate
=
[
self
queue
];
}
if
([
authenticationDelegate
respondsToSelector
:
@selector
(
authenticationNeededForRequest
:)])
{
[
authenticationDelegate
performSelector
:
@selector
(
authenticationNeededForRequest
:)
withObject
:
self
];
return
;
}
#if NS_BLOCKS_AVAILABLE
if
(
authenticationNeededBlock
)
{
authenticationNeededBlock
(
self
);
}
#endif
}
-
(
void
)
attemptToApplyProxyCredentialsAndResume
...
...
@@ -2467,7 +2564,7 @@ static NSOperationQueue *sharedQueue = nil;
[
self
setLastActivityTime
:
nil
];
if
([
self
a
skDelegateForProxyCredentials
])
{
if
([
self
willA
skDelegateForProxyCredentials
])
{
[
self
attemptToApplyProxyCredentialsAndResume
];
[
delegateAuthenticationLock
unlock
];
return
;
...
...
@@ -2539,7 +2636,7 @@ static NSOperationQueue *sharedQueue = nil;
return
;
}
if
([
self
a
skDelegateForProxyCredentials
])
{
if
([
self
willA
skDelegateForProxyCredentials
])
{
[
delegateAuthenticationLock
unlock
];
return
;
}
...
...
@@ -2571,27 +2668,7 @@ static NSOperationQueue *sharedQueue = nil;
#endif
}
-
(
BOOL
)
askDelegateForCredentials
{
// If we have a delegate, we'll see if it can handle proxyAuthenticationNeededForRequest:.
// Otherwise, we'll try the queue (if this request is part of one) and it will pass the message on to its own delegate
id
authenticationDelegate
=
[
self
delegate
];
if
(
!
authenticationDelegate
)
{
authenticationDelegate
=
[
self
queue
];
}
#if NS_BLOCKS_AVAILABLE
if
(
authenticationNeededBlock
)
{
authenticationNeededBlock
(
self
);
}
#endif
if
([
authenticationDelegate
respondsToSelector
:
@selector
(
authenticationNeededForRequest
:)])
{
[
authenticationDelegate
performSelectorOnMainThread
:
@selector
(
authenticationNeededForRequest
:)
withObject
:
self
waitUntilDone
:
[
NSThread
isMainThread
]];
return
YES
;
}
return
NO
;
}
-
(
void
)
attemptToApplyCredentialsAndResume
{
...
...
@@ -2661,7 +2738,7 @@ static NSOperationQueue *sharedQueue = nil;
[
self
setLastActivityTime
:
nil
];
if
([
self
a
skDelegateForCredentials
])
{
if
([
self
willA
skDelegateForCredentials
])
{
[
delegateAuthenticationLock
unlock
];
return
;
}
...
...
@@ -2728,7 +2805,7 @@ static NSOperationQueue *sharedQueue = nil;
}
return
;
}
if
([
self
a
skDelegateForCredentials
])
{
if
([
self
willA
skDelegateForCredentials
])
{
[
delegateAuthenticationLock
unlock
];
return
;
}
...
...
Mac.xcodeproj/project.pbxproj
View file @
8a17855
This diff was suppressed by a .gitattributes entry.
iPhone.xcodeproj/project.pbxproj
View file @
8a17855
This diff was suppressed by a .gitattributes entry.
Please
register
or
login
to post a comment