Fix issue with multipart form boundaries.
The first boundary should not have a preceeding newline. This causes some multipart parsers to miss the inital boundary. An example of a parser facing this issue is node-formidable by felixge.
This commit is contained in:
parent
e37c641656
commit
1561f0392b
1 changed files with 9 additions and 1 deletions
|
|
@ -381,6 +381,10 @@ static NSString * AFPropertyListStringFromParameters(NSDictionary *parameters) {
|
|||
|
||||
#pragma mark -
|
||||
|
||||
static inline NSString * AFMultipartFormInitialBoundary() {
|
||||
return [NSString stringWithFormat:@"--%@%@", kAFMultipartFormBoundary, kAFMultipartFormLineDelimiter];
|
||||
}
|
||||
|
||||
static inline NSString * AFMultipartFormEncapsulationBoundary() {
|
||||
return [NSString stringWithFormat:@"%@--%@%@", kAFMultipartFormLineDelimiter, kAFMultipartFormBoundary, kAFMultipartFormLineDelimiter];
|
||||
}
|
||||
|
|
@ -424,7 +428,11 @@ static inline NSString * AFMultipartFormFinalBoundary() {
|
|||
#pragma mark - AFMultipartFormData
|
||||
|
||||
- (void)appendPartWithHeaders:(NSDictionary *)headers body:(NSData *)body {
|
||||
if ([self.mutableData length] == 0) {
|
||||
[self appendString:AFMultipartFormInitialBoundary()];
|
||||
} else {
|
||||
[self appendString:AFMultipartFormEncapsulationBoundary()];
|
||||
}
|
||||
|
||||
for (NSString *field in [headers allKeys]) {
|
||||
[self appendString:[NSString stringWithFormat:@"%@: %@%@", field, [headers valueForKey:field], kAFMultipartFormLineDelimiter]];
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue