Skip to content

Commit

Permalink
Fixing a few things with AFRestClient multipart request functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mattt committed Sep 21, 2011
1 parent 8b86051 commit 3411536
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions AFNetworking/AFRestClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
@interface AFMutableMultipartFormData : NSObject <AFMultipartFormDataProxy> {
@private
NSStringEncoding _stringEncoding;
NSMutableArray *_lines;
NSMutableArray *_mutableLines;
}

- (id)initWithStringEncoding:(NSStringEncoding)encoding;
Expand Down Expand Up @@ -197,7 +197,7 @@ - (NSMutableURLRequest *)multipartFormRequestWithMethod:(NSString *)method
}

NSMutableURLRequest *request = [self requestWithMethod:method path:path parameters:nil];
__block AFMutableMultipartFormData *formData = [[AFMutableMultipartFormData alloc] init];
__block AFMutableMultipartFormData *formData = [[AFMutableMultipartFormData alloc] initWithStringEncoding:self.stringEncoding];

id key = nil;
NSEnumerator *enumerator = [parameters keyEnumerator];
Expand Down Expand Up @@ -276,14 +276,14 @@ - (void)deletePath:(NSString *)path parameters:(NSDictionary *)parameters succes
// multipart/form-data; see http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.2
@interface AFMutableMultipartFormData ()
@property (readwrite, nonatomic, assign) NSStringEncoding stringEncoding;
@property (readwrite, nonatomic, retain) NSMutableArray *lines;
@property (readwrite, nonatomic, retain) NSMutableArray *mutableLines;

- (void)appendBlankLine;
@end

@implementation AFMutableMultipartFormData
@synthesize stringEncoding = _stringEncoding;
@synthesize lines = _lines;
@synthesize mutableLines = _mutableLines;

- (id)initWithStringEncoding:(NSStringEncoding)encoding {
self = [super init];
Expand All @@ -292,25 +292,31 @@ - (id)initWithStringEncoding:(NSStringEncoding)encoding {
}

self.stringEncoding = encoding;
self.lines = [NSMutableArray array];
self.mutableLines = [NSMutableArray array];

return self;
}

- (void)dealloc {
[_lines release];
[_mutableLines release];
[super dealloc];
}

- (NSData *)data {
NSLog(@"DATA: %@", [[self.lines componentsJoinedByString:kAFMultipartFormLineDelimiter] stringByAppendingString:AFMultipartFormFinalBoundary()]);
if ([self.mutableLines count] == 0) {
return nil;
}

return [[[[self.lines componentsJoinedByString:kAFMultipartFormLineDelimiter] stringByAppendingString:AFMultipartFormFinalBoundary()] stringByAppendingString:kAFMultipartFormLineDelimiter] dataUsingEncoding:self.stringEncoding];
return [[[[self.mutableLines componentsJoinedByString:kAFMultipartFormLineDelimiter] stringByAppendingString:kAFMultipartFormLineDelimiter] stringByAppendingString:AFMultipartFormFinalBoundary()] dataUsingEncoding:self.stringEncoding];
}

#pragma mark - AFMultipartFormDataProxy

- (void)appendPartWithHeaders:(NSDictionary *)headers body:(NSData *)body {
if ([self.mutableLines count] > 0) {
[self appendString:AFMultipartFormEncapsulationBoundary()];
}

for (NSString *field in [headers allKeys]) {
[self appendString:[NSString stringWithFormat:@"%@: %@", field, [headers valueForKey:field]]];
}
Expand Down Expand Up @@ -339,7 +345,7 @@ - (void)appendData:(NSData *)data {
}

- (void)appendString:(NSString *)string {
[self.lines addObject:string];
[self.mutableLines addObject:string];
}

- (void)appendBlankLine {
Expand Down

0 comments on commit 3411536

Please sign in to comment.