From 68ef25cb7c72457d03330c927a37fa1c3e04e6f4 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Thu, 13 Oct 2011 14:32:17 -0500 Subject: [PATCH] [Issue #72] Fixing construction of URL from path relative to base URL, where trailing slash is removed --- AFNetworking/AFHTTPClient.m | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index 9a24ce7..3e2e2a3 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -81,6 +81,15 @@ static NSString * AFBase64EncodedStringFromString(NSString *string) { return [[[NSString alloc] initWithData:mutableData encoding:NSASCIIStringEncoding] autorelease]; } +static NSURL * AFURLWithPathRelativeToURL(NSString *path, NSURL *baseURL) { + NSString *URLString = [[baseURL absoluteString] stringByAppendingPathComponent:path]; + if ([path hasSuffix:@"/"]) { + URLString = [URLString stringByAppendingString:@"/"]; + } + + return [NSURL URLWithString:URLString]; +} + static NSString * AFURLEncodedStringFromString(NSString *string) { static NSString * const kAFLegalCharactersToBeEscaped = @"?!@#$^&%*+,:;='\"`<>()[]{}/\\|~ "; @@ -239,7 +248,7 @@ static NSString * AFPropertyListStringFromParameters(NSDictionary *parameters) { path:(NSString *)path parameters:(NSDictionary *)parameters { - NSURL *url = [self.baseURL URLByAppendingPathComponent:path]; + NSURL *url = AFURLWithPathRelativeToURL(path, self.baseURL); NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] initWithURL:url] autorelease]; [request setHTTPMethod:method]; [request setAllHTTPHeaderFields:self.defaultHeaders];