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
Jamie Pinkham
2010-10-04 20:04:23 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4ea1a615e9d204215807b02eba656b91365b7ad3
4ea1a615
1 parent
d6197f9d
added hooks for request redirects
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
0 deletions
Classes/ASIHTTPRequest.h
Classes/ASIHTTPRequest.m
Classes/ASIHTTPRequestDelegate.h
Classes/ASIHTTPRequest.h
View file @
4ea1a61
...
...
@@ -469,6 +469,9 @@ typedef void (^ASIHTTPRequestDataReceivedBlock)(ASIHTTPRequest *request, NSData
//block for handling proxy authentication
ASIHTTPRequestBlock
proxyAuthenticationNeededBlock
;
//block for handling redirections, if you want to
ASIHTTPRequestBlock
requestRedirectedBlock
;
#endif
}
...
...
@@ -495,6 +498,7 @@ typedef void (^ASIHTTPRequestDataReceivedBlock)(ASIHTTPRequest *request, NSData
-
(
void
)
setDataReceivedBlock
:(
ASIHTTPRequestDataReceivedBlock
)
aReceivedBlock
;
-
(
void
)
setAuthenticationNeededBlock
:(
ASIHTTPRequestBlock
)
anAuthenticationBlock
;
-
(
void
)
setProxyAuthenticationNeededBlock
:(
ASIHTTPRequestBlock
)
aProxyAuthenticationBlock
;
-
(
void
)
setRequestRedirectedBlock
:(
ASIHTTPRequestBlock
)
aRedirectBlock
;
#endif
#pragma mark setup request
...
...
Classes/ASIHTTPRequest.m
View file @
4ea1a61
...
...
@@ -430,6 +430,11 @@ static NSOperationQueue *sharedQueue = nil;
[
proxyAuthenticationNeededBlock
release
];
proxyAuthenticationNeededBlock
=
[
aProxyAuthenticationBlock
copy
];
}
-
(
void
)
setRequestRedirectedBlock
:
(
ASIHTTPRequestBlock
)
aRedirectBlock
{
[
requestRedirectedBlock
release
];
requestRedirectedBlock
=
[
aRedirectBlock
copy
];
}
#endif
#pragma mark setup request
...
...
@@ -1996,6 +2001,16 @@ 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
// 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
// See also:
...
...
Classes/ASIHTTPRequestDelegate.h
View file @
4ea1a61
...
...
@@ -18,6 +18,7 @@
-
(
void
)
requestReceivedResponseHeaders
:(
ASIHTTPRequest
*
)
request
;
-
(
void
)
requestFinished
:(
ASIHTTPRequest
*
)
request
;
-
(
void
)
requestFailed
:(
ASIHTTPRequest
*
)
request
;
-
(
void
)
requestRedirected
:(
ASIHTTPRequest
*
)
request
;
// When a delegate implements this method, it is expected to process all incoming data itself
// This means that responseData / responseString / downloadDestinationPath etc are ignored
...
...
Please
register
or
login
to post a comment