Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions Source/Coders/CMFormCoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,31 @@ - (NSData *)encodeObject:(id)object {
NSStringEncoding encoding = NSUTF8StringEncoding;

NSMutableArray *pairs = [NSMutableArray new];
if (NO == [object isKindOfClass:[NSDictionary class]]) {
return nil;
}

for (NSString *key in [object allKeys]) {
id value = [object valueForKey:key];
if (NO == [value isKindOfClass:[NSString class]]) {
if ([value respondsToSelector:@selector(description)]) {
value = [value description];

NSData *payloadData = nil;

if (YES == [object isKindOfClass:[NSDictionary class]]) {
for (NSString *key in [object allKeys]) {
id value = [object valueForKey:key];
if (NO == [value isKindOfClass:[NSString class]]) {
if ([value respondsToSelector:@selector(description)]) {
value = [value description];
}
}
value = [self urlencodeString:value withEncoding:encoding];
[pairs addObject:[NSString stringWithFormat:@"%@=%@", key, value]];
}
value = [self urlencodeString:value withEncoding:encoding];
[pairs addObject:[NSString stringWithFormat:@"%@=%@", key, value]];
NSString *payloadString = [pairs componentsJoinedByString:@"&"];
payloadData = [payloadString dataUsingEncoding:encoding];
}
else if (YES == [object isKindOfClass:[NSString class]]) {
// Preformatted payload string of form @"key1=value1&key2=value2"
NSAssert([object containsString:@"="], @"A form payload of type NSString should contain key=value pairs");
NSString *payloadString = (NSString *)object;
payloadData = [payloadString dataUsingEncoding:encoding];
}
NSString *payloadString = [pairs componentsJoinedByString:@"&"];
return [payloadString dataUsingEncoding:encoding];

return payloadData;
}


Expand Down
3 changes: 3 additions & 0 deletions Source/Request/CMRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@
/** When set, the request will include the appropriate 'Range' and 'if-Range' along with 'ETag' and/or 'Last-Modified' headers to request a range of the resource. */
@property (nonatomic) CMContentRange range;

// The URL if any to which the request was redirected; nil otherwise.
@property (nonatomic, strong) NSString *redirectURL;



// ========================================================================== //
Expand Down
7 changes: 7 additions & 0 deletions Source/Request/CMRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,13 @@ - (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticatio


- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response {
NSHTTPURLResponse *httpURLResponse = (NSHTTPURLResponse *)response;
if (httpURLResponse) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test can be removed because nil.statusCode will be 0.

if (httpURLResponse.statusCode >= kHTTPStatusMultipleChoices && httpURLResponse.statusCode < kHTTPStatusBadRequest) {
// it's a redirect

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to see:
if (statusCode == HTTPMovedPermanently || statusCode == HTTPFound)

Was there a reason you chose this range?

self.redirectURL = [[httpURLResponse allHeaderFields] valueForKey:@"Location"];
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add kCumulusHTTPHeaderLocation to the list of header constants in CMConstants.h and use that instead.

}
if (response && self.authProviders.count > 0) {
NSMutableURLRequest *authorizedRequest = [request mutableCopy];
for (id<CMAuthProvider> authProvider in self.authProviders) {
Expand Down