incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hermw...@apache.org
Subject [20/20] ios commit: [CB-765] Header Support iOS FileTransfer upload
Date Wed, 27 Jun 2012 18:33:51 GMT
[CB-765] Header Support iOS FileTransfer upload


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/43f78929
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/43f78929
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/43f78929

Branch: refs/heads/master
Commit: 43f789295ff45cfca071dd7c788c602db1124d5c
Parents: 850a08b
Author: hermwong <herm.wong@gmail.com>
Authored: Wed Jun 27 10:35:51 2012 -0700
Committer: hermwong <herm.wong@gmail.com>
Committed: Wed Jun 27 10:35:51 2012 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVFileTransfer.m |   28 ++++++++++++++++++++++++----
 1 files changed, 24 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/43f78929/CordovaLib/Classes/CDVFileTransfer.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFileTransfer.m b/CordovaLib/Classes/CDVFileTransfer.m
index 9a3ab53..8d0d7fa 100644
--- a/CordovaLib/Classes/CDVFileTransfer.m
+++ b/CordovaLib/Classes/CDVFileTransfer.m
@@ -103,16 +103,36 @@
     //Content-Type: multipart/form-data; boundary=*****org.apache.cordova.formBoundary
 	[req setValue:@"XMLHttpRequest" forHTTPHeaderField:@"X-Requested-With"];
 	NSString* userAgent = [[self.webView request] valueForHTTPHeaderField:@"User-agent"];
-	if(userAgent) {
+	
+    if(userAgent) {
 		[req setValue: userAgent forHTTPHeaderField:@"User-Agent"];
 	}
-
+	
+    NSMutableDictionary* headers = [params objectForKey:@"headers"];
+    NSEnumerator *enumerator = [headers keyEnumerator];
+	id val;
+   	NSString *nkey;
+    
+	while (nkey = [enumerator nextObject]) {
+		val = [headers objectForKey:nkey];
+		if(!val || val == [NSNull null]) {
+			continue;	
+		}
+		// if it responds to stringValue selector (eg NSNumber) get the NSString
+		if ([val respondsToSelector:@selector(stringValue)]) {
+			val = [val stringValue];
+		}
+		// finally, check whether it is a NSString (for dataUsingEncoding selector below)
+		if (![val isKindOfClass:[NSString class]]) {
+			continue;
+		}
+        
+        [req setValue:val forHTTPHeaderField:nkey];	
+    }
     
 	NSMutableData *postBody = [NSMutableData data];
 	
-	NSEnumerator *enumerator = [params keyEnumerator];
 	id key;
-	id val;
 	
 	while ((key = [enumerator nextObject])) {
 		val = [params objectForKey:key];


Mime
View raw message