Skip to content

Commit

Permalink
[#42] cleaned up url , changed Dog tests to use no user
Browse files Browse the repository at this point in the history
  • Loading branch information
jjburka committed Feb 19, 2009
1 parent bb0dcef commit 7aa4e07
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Classes/DogTest.m
Expand Up @@ -20,7 +20,8 @@ -(void) setUp {
[ObjectiveResourceConfig setSite:@"http://localhost:36313/"];
[ObjectiveResourceConfig setResponseType:JSONResponse];
//[ObjectiveResource setResponseType:XmlResponse];

[ObjectiveResourceConfig setUser:nil];
[ObjectiveResourceConfig setPassword:nil];
owner = [Person findRemote:[NSString stringWithFormat:@"%i",DOG_OWNER]];
}

Expand Down
18 changes: 9 additions & 9 deletions Classes/lib/Connection.m
Expand Up @@ -49,14 +49,14 @@ + (Response *)sendRequest:(NSMutableURLRequest *)request withUser:(NSString *)us

//lots of servers fail to implement http basic authentication correctly, so we pass the credentials even if they are not asked for
//TODO make this configurable?
NSString *authString = [[[NSString stringWithFormat:@"%@:%@",user, password] dataUsingEncoding:NSUTF8StringEncoding] base64Encoding];
[request addValue:[NSString stringWithFormat:@"Basic %@", authString] forHTTPHeaderField:@"Authorization"];
NSString *escapedUser = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(CFStringRef)user, NULL, (CFStringRef)@"@.:", kCFStringEncodingUTF8);
NSString *escapedPassword = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(CFStringRef)password, NULL, (CFStringRef)@"@.:", kCFStringEncodingUTF8);
NSURL *url = [request URL];
if(escapedUser && escapedPassword) {
if(user && password) {
NSString *authString = [[[NSString stringWithFormat:@"%@:%@",user, password] dataUsingEncoding:NSUTF8StringEncoding] base64Encoding];
[request addValue:[NSString stringWithFormat:@"Basic %@", authString] forHTTPHeaderField:@"Authorization"];
NSString *escapedUser = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(CFStringRef)user, NULL, (CFStringRef)@"@.:", kCFStringEncodingUTF8);
NSString *escapedPassword = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(CFStringRef)password, NULL, (CFStringRef)@"@.:", kCFStringEncodingUTF8);
NSMutableString *urlString = [NSMutableString stringWithFormat:@"%@://%@:%@@%@",[url scheme],escapedUser,escapedPassword,[url host],nil];
if([url port]) {
[urlString appendFormat:@":%@",[url port],nil];
Expand All @@ -66,6 +66,8 @@ + (Response *)sendRequest:(NSMutableURLRequest *)request withUser:(NSString *)us
[urlString appendFormat:@"?%@",[url query],nil];
}
[request setURL:url];
[escapedUser release];
[escapedPassword release];
}


Expand All @@ -90,8 +92,6 @@ + (Response *)sendRequest:(NSMutableURLRequest *)request withUser:(NSString *)us
andError:connectionDelegate.error];
[resp log];

[escapedUser release];
[escapedPassword release];
[activeDelegates removeObject:connectionDelegate];

//if there are no more active delegates release the array
Expand Down

0 comments on commit 7aa4e07

Please sign in to comment.