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-10-06 10:50:30 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d310696cb9b5116b3b888e94dbd4cc94e8bd32af
d310696c
1 parent
8017db2a
Added [request startAsynchronous] for easy async requests (no queue required!)
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
2 deletions
Classes/ASIHTTPRequest.h
Classes/ASIHTTPRequest.m
Classes/Tests/ASIHTTPRequestTests.m
Classes/ASIHTTPRequest.h
View file @
d310696
...
...
@@ -343,6 +343,12 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
// Returns true if the response was gzip compressed
-
(
BOOL
)
isResponseCompressed
;
#pragma mark running a request
// Run a request asynchronously by adding it to the global queue
// (Use [request start] for a synchronous request)
-
(
void
)
startAsynchronous
;
#pragma mark request logic
// Main request loop is in here
...
...
@@ -418,7 +424,11 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
-
(
void
)
handleStreamComplete
;
-
(
void
)
handleStreamError
;
# pragma mark session credentials
#pragma mark global queue
+
(
NSOperationQueue
*
)
sharedRequestQueue
;
#pragma mark session credentials
+
(
NSMutableArray
*
)
sessionProxyCredentialsStore
;
+
(
NSMutableArray
*
)
sessionCredentialsStore
;
...
...
Classes/ASIHTTPRequest.m
View file @
d310696
...
...
@@ -93,6 +93,8 @@ static NSRecursiveLock *sessionCookiesLock = nil;
// This is so it can make use of any credentials supplied for the other request, if they are appropriate
static
NSRecursiveLock
*
delegateAuthenticationLock
=
nil
;
static
NSOperationQueue
*
sharedRequestQueue
=
nil
;
// Private stuff
@interface
ASIHTTPRequest
()
...
...
@@ -403,6 +405,15 @@ static NSRecursiveLock *delegateAuthenticationLock = nil;
}
}
#pragma mark running a request
// Run a request asynchronously by adding it to the global queue
// (Use [request start] for a synchronous request)
-
(
void
)
startAsynchronous
{
[[
ASIHTTPRequest
sharedRequestQueue
]
addOperation
:
self
];
}
#pragma mark request logic
...
...
@@ -2088,6 +2099,17 @@ static NSRecursiveLock *delegateAuthenticationLock = nil;
[
super
cancel
];
}
#pragma mark global queue
+
(
NSOperationQueue
*
)
sharedRequestQueue
{
if
(
!
sharedRequestQueue
)
{
sharedRequestQueue
=
[[
NSOperationQueue
alloc
]
init
];
[
sharedRequestQueue
setMaxConcurrentOperationCount
:
YES
];
}
return
sharedRequestQueue
;
}
# pragma mark session credentials
+
(
NSMutableArray
*
)
sessionProxyCredentialsStore
...
...
Classes/Tests/ASIHTTPRequestTests.m
View file @
d310696
...
...
@@ -923,7 +923,64 @@
GHAssertTrue
(
success
,
@"Got wrong response status message"
);
}
-
(
void
)
testAsynchronousWithGlobalQueue
{
ASIHTTPRequest
*
request
=
[
ASIHTTPRequest
requestWithURL
:[
NSURL
URLWithString
:
@"http://allseeing-i.com/ASIHTTPRequest/tests/first"
]];
[
request
setUserInfo
:[
NSDictionary
dictionaryWithObject
:[
NSNumber
numberWithInt
:
1
]
forKey
:
@"RequestNumber"
]];
[
request
setDidFailSelector
:
@selector
(
asyncFail
:)];
[
request
setDidFinishSelector
:
@selector
(
asyncSuccess
:)];
[
request
setDelegate
:
self
];
[
request
startAsynchronous
];
@end
request
=
[
ASIHTTPRequest
requestWithURL
:[
NSURL
URLWithString
:
@"http://allseeing-i.com/ASIHTTPRequest/tests/second"
]];
[
request
setUserInfo
:[
NSDictionary
dictionaryWithObject
:[
NSNumber
numberWithInt
:
2
]
forKey
:
@"RequestNumber"
]];
[
request
setDidFailSelector
:
@selector
(
asyncFail
:)];
[
request
setDidFinishSelector
:
@selector
(
asyncSuccess
:)];
[
request
setDelegate
:
self
];
[
request
startAsynchronous
];
request
=
[
ASIHTTPRequest
requestWithURL
:[
NSURL
URLWithString
:
@"http://allseeing-i.com/ASIHTTPRequest/tests/third"
]];
[
request
setUserInfo
:[
NSDictionary
dictionaryWithObject
:[
NSNumber
numberWithInt
:
3
]
forKey
:
@"RequestNumber"
]];
[
request
setDidFailSelector
:
@selector
(
asyncFail
:)];
[
request
setDidFinishSelector
:
@selector
(
asyncSuccess
:)];
[
request
setDelegate
:
self
];
[
request
startAsynchronous
];
request
=
[
ASIHTTPRequest
requestWithURL
:
nil
];
[
request
setUserInfo
:[
NSDictionary
dictionaryWithObject
:[
NSNumber
numberWithInt
:
4
]
forKey
:
@"RequestNumber"
]];
[
request
setDidFailSelector
:
@selector
(
asyncFail
:)];
[
request
setDidFinishSelector
:
@selector
(
asyncSuccess
:)];
[
request
setDelegate
:
self
];
[
request
startAsynchronous
];
}
-
(
void
)
asyncFail
:
(
ASIHTTPRequest
*
)
request
{
int
requestNumber
=
[[[
request
userInfo
]
objectForKey
:
@"RequestNumber"
]
intValue
];
GHAssertEquals
(
requestNumber
,
4
,
@"Wrong request failed"
);
}
-
(
void
)
asyncSuccess
:
(
ASIHTTPRequest
*
)
request
{
int
requestNumber
=
[[[
request
userInfo
]
objectForKey
:
@"RequestNumber"
]
intValue
];
GHAssertNotEquals
(
requestNumber
,
4
,
@"Request succeeded when it should have failed"
);
BOOL
success
;
switch
(
requestNumber
)
{
case
1
:
success
=
[[
request
responseString
]
isEqualToString
:
@"This is the expected content for the first string"
];
break
;
case
2
:
success
=
[[
request
responseString
]
isEqualToString
:
@"This is the expected content for the second string"
];
break
;
case
3
:
success
=
[[
request
responseString
]
isEqualToString
:
@"This is the expected content for the third string"
];
break
;
}
GHAssertTrue
(
success
,
@"Got wrong request content - very bad!"
);
}
@end
\ No newline at end of file
...
...
Please
register
or
login
to post a comment