Permalink
Browse files

Implement a way to set the character set for a multiform post.

TTURLRequest.charsetForMultipart can now be set to whatever NSStringEncoding
you need to make the post with.
  • Loading branch information...
1 parent 2f50247 commit d8a67871b824555075f6be82614bd1eef61b0c1c Tobias Rundström committed with jverkoey Nov 25, 2009
Showing with 19 additions and 9 deletions.
  1. +11 −9 src/TTURLRequest.m
  2. +8 −0 src/Three20/TTURLRequest.h
View
@@ -33,7 +33,8 @@ @implementation TTURLRequest
timestamp = _timestamp, userInfo = _userInfo, isLoading = _isLoading,
shouldHandleCookies = _shouldHandleCookies, totalBytesLoaded = _totalBytesLoaded,
totalBytesExpected = _totalBytesExpected, respondedFromCache = _respondedFromCache,
- headers = _headers, filterPasswordLogging = _filterPasswordLogging;
+ headers = _headers, filterPasswordLogging = _filterPasswordLogging,
+ charsetForMultipart = _charsetForMultipart;
+ (TTURLRequest*)request {
return [[[TTURLRequest alloc] init] autorelease];
@@ -75,6 +76,7 @@ - (id)init {
_totalBytesExpected = 0;
_respondedFromCache = NO;
_filterPasswordLogging = NO;
+ _charsetForMultipart = NSUTF8StringEncoding;
}
return self;
}
@@ -145,8 +147,8 @@ - (NSData*)generatePostBody {
[body appendData:[beginLine dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString
stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", key]
- dataUsingEncoding:NSUTF8StringEncoding]];
- [body appendData:[value dataUsingEncoding:NSUTF8StringEncoding]];
+ dataUsingEncoding:_charsetForMultipart]];
+ [body appendData:[value dataUsingEncoding:_charsetForMultipart]];
}
}
@@ -161,13 +163,13 @@ - (NSData*)generatePostBody {
[body appendData:[[NSString stringWithFormat:
@"Content-Disposition: form-data; name=\"%@\"; filename=\"image.jpg\"\r\n",
key]
- dataUsingEncoding:NSUTF8StringEncoding]];
+ dataUsingEncoding:_charsetForMultipart]];
[body appendData:[[NSString
stringWithFormat:@"Content-Length: %d\r\n", data.length]
- dataUsingEncoding:NSUTF8StringEncoding]];
+ dataUsingEncoding:_charsetForMultipart]];
[body appendData:[[NSString
stringWithString:@"Content-Type: image/jpeg\r\n\r\n"]
- dataUsingEncoding:NSUTF8StringEncoding]];
+ dataUsingEncoding:_charsetForMultipart]];
[body appendData:data];
imageKey = key;
}
@@ -182,11 +184,11 @@ - (NSData*)generatePostBody {
[body appendData:[[NSString stringWithFormat:
@"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n",
fileName, fileName]
- dataUsingEncoding:NSUTF8StringEncoding]];
+ dataUsingEncoding:_charsetForMultipart]];
[body appendData:[[NSString stringWithFormat:@"Content-Length: %d\r\n", data.length]
- dataUsingEncoding:NSUTF8StringEncoding]];
+ dataUsingEncoding:_charsetForMultipart]];
[body appendData:[[NSString stringWithFormat:@"Content-Type: %@\r\n\r\n", mimeType]
- dataUsingEncoding:NSUTF8StringEncoding]];
+ dataUsingEncoding:_charsetForMultipart]];
[body appendData:data];
}
@@ -39,6 +39,7 @@
BOOL _shouldHandleCookies;
BOOL _respondedFromCache;
BOOL _filterPasswordLogging;
+ NSStringEncoding _charsetForMultipart;
}
/**
@@ -112,6 +113,13 @@
*/
@property(nonatomic,assign) BOOL filterPasswordLogging;
+/**
+ * Charset to use when creating multipart/form-data data.
+ * The default is NSUTF8StringEncoding to remain backwards
+ * compatible
+ */
+@property(nonatomic) NSStringEncoding charsetForMultipart;
+
+ (TTURLRequest*)request;
+ (TTURLRequest*)requestWithURL:(NSString*)URL delegate:(id<TTURLRequestDelegate>)delegate;

0 comments on commit d8a6787

Please sign in to comment.