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-08-23 12:53:35 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
bb60fa7051170abf31cd7a8865d0375b9474ae80
bb60fa70
1 parent
61ff892e
Bug fixes and tweaks
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
49 deletions
Classes/ASIAuthenticationDialog.m
Classes/ASINetworkQueue.m
Classes/Tests/ASINetworkQueueTests.m
iPhone Sample/AuthenticationViewController.m
Classes/ASIAuthenticationDialog.m
View file @
bb60fa7
...
...
@@ -55,21 +55,40 @@ NSLock *dialogLock = nil;
[[
self
loginDialog
]
setDelegate
:
self
];
// We show the login form in a table view, similar to Safari's authentication dialog
UITableView
*
table
=
[[[
UITableView
alloc
]
initWithFrame
:
CGRectMake
(
0
,
5
0
,
320
,
480
)
style
:
UITableViewStyleGrouped
]
autorelease
];
UITableView
*
table
=
[[[
UITableView
alloc
]
initWithFrame
:
CGRectMake
(
0
,
8
0
,
320
,
480
)
style
:
UITableViewStyleGrouped
]
autorelease
];
[
table
setDelegate
:
self
];
[
table
setDataSource
:
self
];
[[
self
loginDialog
]
addSubview
:
table
];
[[
self
loginDialog
]
showInView
:[[[
UIApplication
sharedApplication
]
windows
]
objectAtIndex
:
0
]];
[[
self
loginDialog
]
setFrame
:
CGRectMake
(
0
,
0
,
320
,
480
)];
UIToolbar
*
toolbar
=
[[[
UIToolbar
alloc
]
initWithFrame
:
CGRectMake
(
0
,
0
,
320
,
80
)]
autorelease
];
//[toolbar setFrame:CGRectMake(0,20,320,50)];
// Setup the title (Couldn't figure out how to put this in the same toolbar as the buttons)
UIToolbar
*
titleBar
=
[[[
UIToolbar
alloc
]
initWithFrame
:
CGRectMake
(
0
,
0
,
320
,
30
)]
autorelease
];
UILabel
*
label
=
[[
UILabel
alloc
]
initWithFrame
:
CGRectMake
(
10
,
0
,
300
,
30
)];
if
([
self
type
]
==
ASIProxyAuthenticationType
)
{
[
label
setText
:
@"Login to this secure proxy server."
];
}
else
{
[
label
setText
:
@"Login to this secure server."
];
}
[
label
setTextColor
:[
UIColor
blackColor
]];
[
label
setFont
:[
UIFont
systemFontOfSize
:
13
.
0
]];
[
label
setShadowColor
:[
UIColor
colorWithRed
:
1
green
:
1
blue
:
1
alpha
:
0
.
5
]];
[
label
setShadowOffset
:
CGSizeMake
(
0
,
1
.
0
)];
[
label
setOpaque
:
NO
];
[
label
setBackgroundColor
:
nil
];
[
label
setTextAlignment
:
UITextAlignmentCenter
];
[
titleBar
addSubview
:
label
];
[[
self
loginDialog
]
addSubview
:
titleBar
];
// Setup the toolbar
UIToolbar
*
toolbar
=
[[[
UIToolbar
alloc
]
initWithFrame
:
CGRectMake
(
0
,
30
,
320
,
50
)]
autorelease
];
NSMutableArray
*
items
=
[[[
NSMutableArray
alloc
]
init
]
autorelease
];
UIBarButtonItem
*
backButton
=
[[[
UIBarButtonItem
alloc
]
initWithBarButtonSystemItem
:
UIBarButtonSystemItemCancel
target
:
self
action
:
@selector
(
cancelAuthenticationFromDialog
:)]
autorelease
];
//[backButton setContentEdgeInsets:UIEdgeInsetsMake(0,20,0,0)];
[
items
addObject
:
backButton
];
UILabel
*
label
=
[[
UILabel
alloc
]
initWithFrame
:
CGRectMake
(
0
,
0
,
170
,
50
)];
label
=
[[
UILabel
alloc
]
initWithFrame
:
CGRectMake
(
0
,
0
,
170
,
50
)];
[
label
setText
:[[[
self
request
]
url
]
host
]];
[
label
setTextColor
:[
UIColor
whiteColor
]];
[
label
setFont
:[
UIFont
boldSystemFontOfSize
:
22
.
0
]];
...
...
@@ -82,12 +101,17 @@ NSLock *dialogLock = nil;
[
toolbar
addSubview
:
label
];
UIBarButtonItem
*
labelButton
=
[[[
UIBarButtonItem
alloc
]
initWithBarButtonSystemItem
:
UIBarButtonSystemItemCancel
target
:
nil
action
:
nil
]
autorelease
];
//[labelButton setCustomView:label];
//[items addObject:labelButton];
[
labelButton
setCustomView
:
label
];
[
items
addObject
:
labelButton
];
[
items
addObject
:[[[
UIBarButtonItem
alloc
]
initWithTitle
:
@"Login"
style
:
UIBarButtonItemStyleDone
target
:
self
action
:
@selector
(
loginWithCredentialsFromDialog
:)]
autorelease
]];
[
toolbar
setItems
:
items
];
[[
self
loginDialog
]
addSubview
:
toolbar
];
// Force reload the table content, and focus the first field to show the keyboard
[
table
reloadData
];
[[[[
table
cellForRowAtIndexPath
:[
NSIndexPath
indexPathForRow
:
0
inSection
:
0
]]
subviews
]
objectAtIndex
:
2
]
becomeFirstResponder
];
}
-
(
void
)
cancelAuthenticationFromDialog
:
(
id
)
sender
...
...
@@ -164,10 +188,12 @@ NSLock *dialogLock = nil;
-
(
NSString
*
)
tableView
:
(
UITableView
*
)
tableView
titleForFooterInSection
:
(
NSInteger
)
section
{
if
(
section
==
[
self
numberOfSectionsInTableView
:
tableView
]
-
1
)
{
if
([[[[
self
request
]
url
]
scheme
]
isEqualToString
:
@"https"
])
{
return
@"Password will be sent securely."
;
}
else
{
// If we're using Basic authentication and the connection is not using SSL, we'll show the plain text message
if
([[[
self
request
]
authenticationScheme
]
isEqualToString
:(
NSString
*
)
kCFHTTPAuthenticationSchemeBasic
]
&&
!
[[[[
self
request
]
url
]
scheme
]
isEqualToString
:
@"https"
])
{
return
@"Password will be sent in the clear."
;
// We are using Digest, NTLM, or any scheme over SSL
}
else
{
return
@"Password will be sent securely."
;
}
}
return
nil
;
...
...
Classes/ASINetworkQueue.m
View file @
bb60fa7
...
...
@@ -267,26 +267,32 @@
[
ASIHTTPRequest
setProgress
:
progress
forProgressIndicator
:[
self
downloadProgressDelegate
]];
}
// Since this queue takes over as the delegate for all requests it contains, it should forward authorisation requests to its own delegate
-
(
void
)
auth
oriz
ationNeededForRequest
:
(
ASIHTTPRequest
*
)
request
-
(
void
)
auth
entic
ationNeededForRequest
:
(
ASIHTTPRequest
*
)
request
{
if
([[
self
delegate
]
respondsToSelector
:
@selector
(
auth
oriz
ationNeededForRequest
:)])
{
[[
self
delegate
]
performSelector
:
@selector
(
auth
oriz
ationNeededForRequest
:)
withObject
:
request
];
if
([[
self
delegate
]
respondsToSelector
:
@selector
(
auth
entic
ationNeededForRequest
:)])
{
[[
self
delegate
]
performSelector
:
@selector
(
auth
entic
ationNeededForRequest
:)
withObject
:
request
];
}
}
-
(
void
)
proxyAuth
oriz
ationNeededForRequest
:
(
ASIHTTPRequest
*
)
request
-
(
void
)
proxyAuth
entic
ationNeededForRequest
:
(
ASIHTTPRequest
*
)
request
{
if
([[
self
delegate
]
respondsToSelector
:
@selector
(
proxyAuth
oriz
ationNeededForRequest
:)])
{
[[
self
delegate
]
performSelector
:
@selector
(
proxyAuth
oriz
ationNeededForRequest
:)
withObject
:
request
];
if
([[
self
delegate
]
respondsToSelector
:
@selector
(
proxyAuth
entic
ationNeededForRequest
:)])
{
[[
self
delegate
]
performSelector
:
@selector
(
proxyAuth
entic
ationNeededForRequest
:)
withObject
:
request
];
}
}
-
(
BOOL
)
respondsToSelector
:
(
SEL
)
selector
{
if
(
selector
==
@selector
(
authorizationNeededForRequest
:
))
{
if
([[
self
delegate
]
respondsToSelector
:
@selector
(
authorizationNeededForRequest
:)])
{
if
(
selector
==
@selector
(
authenticationNeededForRequest
:
))
{
if
([[
self
delegate
]
respondsToSelector
:
@selector
(
authenticationNeededForRequest
:)])
{
return
YES
;
}
return
NO
;
}
else
if
(
selector
==
@selector
(
proxyAuthenticationNeededForRequest
:
))
{
if
([[
self
delegate
]
respondsToSelector
:
@selector
(
proxyAuthenticationNeededForRequest
:)])
{
return
YES
;
}
return
NO
;
...
...
Classes/Tests/ASINetworkQueueTests.m
View file @
bb60fa7
...
...
@@ -355,7 +355,7 @@ IMPORTANT
}
-
(
void
)
auth
oriz
ationNeededForRequest
:
(
ASIHTTPRequest
*
)
request
-
(
void
)
auth
entic
ationNeededForRequest
:
(
ASIHTTPRequest
*
)
request
{
// We're using this method in multiple tests:
// testProgressWithAuthentication will set a userInfo dictionary on the main request, to tell us not to supply credentials
...
...
iPhone Sample/AuthenticationViewController.m
View file @
bb60fa7
...
...
@@ -45,31 +45,31 @@
[
topSecretInfo
setFont
:[
UIFont
boldSystemFontOfSize
:
12
]];
}
//- (void)authoriz
ationNeededForRequest:(ASIHTTPRequest *)request
//
{
//
// Why oh why is there no contextInfo for alertView like on Mac OS ?!
//
[self setRequestRequiringProxyAuthentication:nil];
//
[self setRequestRequiringAuthentication:request];
//
// [ASIHTTPRequest showAuthenticationDialogForRequest:request];
//
// //UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Please Login" message:[request authenticationRealm] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil] autorelease];
// // These are undocumented, use at your own risk!
// // A better general approach would be to subclass UIAlertView
// //[alertView addTextFieldWithValue:@"" label:@"Username
"];
// //[alertView addTextFieldWithValue:@"" label:@"Password"
];
//
//
}
//
//- (void)proxyAuthoriz
ationNeededForRequest:(ASIHTTPRequest *)request
//
{
//
[self setRequestRequiringAuthentication:nil];
//
[self setRequestRequiringProxyAuthentication:request];
//
UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Please Login to proxy" message:[request authenticationRealm] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil] autorelease];
//
[alertView addTextFieldWithValue:@"" label:@"Username"];
//
[alertView addTextFieldWithValue:@"" label:@"Password"];
//
[alertView show];
//
}
-
(
void
)
authentic
ationNeededForRequest
:
(
ASIHTTPRequest
*
)
request
{
// Why oh why is there no contextInfo for alertView like on Mac OS ?!
[
self
setRequestRequiringProxyAuthentication
:
nil
];
[
self
setRequestRequiringAuthentication
:
request
];
UIAlertView
*
alertView
=
[[[
UIAlertView
alloc
]
initWithTitle
:
@"Please Login"
message
:[
request
authenticationRealm
]
delegate
:
self
cancelButtonTitle
:
@"Cancel"
otherButtonTitles
:
@"OK"
,
nil
]
autorelease
];
// These are undocumented, use at your own risk!
// A better general approach would be to subclass UIAlertView, or just use ASIHTTPRequest's built-in dialog
[
alertView
addTextFieldWithValue
:
@""
label
:
@"Username"
];
[
alertView
addTextFieldWithValue
:
@""
label
:
@"Password
"
];
[
alertView
show
];
}
-
(
void
)
proxyAuthentic
ationNeededForRequest
:
(
ASIHTTPRequest
*
)
request
{
[
self
setRequestRequiringAuthentication
:
nil
];
[
self
setRequestRequiringProxyAuthentication
:
request
];
UIAlertView
*
alertView
=
[[[
UIAlertView
alloc
]
initWithTitle
:
@"Please Login to proxy"
message
:[
request
authenticationRealm
]
delegate
:
self
cancelButtonTitle
:
@"Cancel"
otherButtonTitles
:
@"OK"
,
nil
]
autorelease
];
[
alertView
addTextFieldWithValue
:
@""
label
:
@"Username"
];
[
alertView
addTextFieldWithValue
:
@""
label
:
@"Password"
];
[
alertView
show
];
}
...
...
@@ -86,14 +86,22 @@
[[
self
requestRequiringProxyAuthentication
]
retryWithAuthentication
];
}
}
else
{
if
([
self
requestRequiringAuthentication
])
{
[[
self
requestRequiringAuthentication
]
cancelLoad
];
}
else
{
[[
self
requestRequiringProxyAuthentication
]
cancelLoad
];
[[
self
requestRequiringAuthentication
]
cancelAuthentication
];
}
}
-
(
BOOL
)
respondsToSelector
:
(
SEL
)
selector
{
if
(
selector
==
@selector
(
authenticationNeededForRequest
:
)
||
selector
==
@selector
(
proxyAuthenticationNeededForRequest
:
))
{
if
([
useBuiltInDialog
isOn
])
{
return
NO
;
}
return
YES
;
}
return
[
super
respondsToSelector
:
selector
];
}
-
(
void
)
didReceiveMemoryWarning
{
[
super
didReceiveMemoryWarning
];
}
...
...
Please
register
or
login
to post a comment