You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2015/05/12 02:52:34 UTC
[1/3] cordova-plugin-file-transfer git commit: CB-8721 Fixes
incorrect headers and upload params parsing on wp8
Repository: cordova-plugin-file-transfer
Updated Branches:
refs/heads/master 3effd7f1f -> f1e41ac1f
CB-8721 Fixes incorrect headers and upload params parsing on wp8
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/21fb03aa
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/21fb03aa
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/21fb03aa
Branch: refs/heads/master
Commit: 21fb03aa9c55fbd1ca4df6097b466840e91c16b8
Parents: 30eb233
Author: Vladimir Kotikov <v-...@microsoft.com>
Authored: Tue Mar 24 11:19:19 2015 +0300
Committer: Vladimir Kotikov <v-...@microsoft.com>
Committed: Tue Mar 24 11:46:51 2015 +0300
----------------------------------------------------------------------
src/wp/FileTransfer.cs | 41 ++++++++++++++++++-----------------------
www/FileTransfer.js | 23 +++++++++++++++++++++++
2 files changed, 41 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/21fb03aa/src/wp/FileTransfer.cs
----------------------------------------------------------------------
diff --git a/src/wp/FileTransfer.cs b/src/wp/FileTransfer.cs
index 11db284..8e234cd 100644
--- a/src/wp/FileTransfer.cs
+++ b/src/wp/FileTransfer.cs
@@ -16,11 +16,13 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.IO.IsolatedStorage;
+using System.Linq;
using System.Net;
using System.Runtime.Serialization;
using System.Windows;
using System.Security;
using System.Diagnostics;
+using WPCordovaClassLib.Cordova.JSON;
namespace WPCordovaClassLib.Cordova.Commands
{
@@ -210,6 +212,19 @@ namespace WPCordovaClassLib.Cordova.Commands
}
/// <summary>
+ /// Represents a request header passed from Javascript to upload/download operations
+ /// </summary>
+ [DataContract]
+ protected struct Header
+ {
+ [DataMember(Name = "name")]
+ public string Name;
+
+ [DataMember(Name = "value")]
+ public string Value;
+ }
+
+ /// <summary>
/// Upload options
/// </summary>
//private TransferOptions uploadOptions;
@@ -311,34 +326,14 @@ namespace WPCordovaClassLib.Cordova.Commands
{
try
{
- Dictionary<string, string> result = new Dictionary<string, string>();
-
- string temp = jsonHeaders.StartsWith("{") ? jsonHeaders.Substring(1) : jsonHeaders;
- temp = temp.EndsWith("}") ? temp.Substring(0, temp.Length - 1) : temp;
-
- string[] strHeaders = temp.Split(',');
- for (int n = 0; n < strHeaders.Length; n++)
- {
- // we need to use indexOf in order to WP7 compatible
- int splitIndex = strHeaders[n].IndexOf(':');
- if (splitIndex > 0)
- {
- string[] split = new string[2];
- split[0] = strHeaders[n].Substring(0, splitIndex);
- split[1] = strHeaders[n].Substring(splitIndex + 1);
-
- split[0] = JSON.JsonHelper.Deserialize<string>(split[0]);
- split[1] = JSON.JsonHelper.Deserialize<string>(split[1]);
- result[split[0]] = split[1];
- }
- }
- return result;
+ return JsonHelper.Deserialize<Header[]>(jsonHeaders)
+ .ToDictionary(header => header.Name, header => header.Value);
}
catch (Exception)
{
Debug.WriteLine("Failed to parseHeaders from string :: " + jsonHeaders);
}
- return null;
+ return new Dictionary<string, string>();
}
public void download(string options)
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/21fb03aa/www/FileTransfer.js
----------------------------------------------------------------------
diff --git a/www/FileTransfer.js b/www/FileTransfer.js
index 17fb782..5db3fec 100644
--- a/www/FileTransfer.js
+++ b/www/FileTransfer.js
@@ -63,6 +63,20 @@ function getBasicAuthHeader(urlString) {
return header;
}
+function convertHeadersToArray(headers) {
+ var result = [];
+ for (var header in headers) {
+ if (headers.hasOwnProperty(header)) {
+ var headerValue = headers[header];
+ result.push({
+ name: header,
+ value: headerValue.toString()
+ });
+ }
+ }
+ return result;
+}
+
var idCounter = 0;
/**
@@ -125,6 +139,11 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro
}
}
+ if (cordova.platformId === "windowsphone") {
+ headers = headers && convertHeadersToArray(headers);
+ params = params && convertHeadersToArray(params);
+ }
+
var fail = errorCallback && function(e) {
var error = new FileTransferError(e.code, e.source, e.target, e.http_status, e.body, e.exception);
errorCallback(error);
@@ -170,6 +189,10 @@ FileTransfer.prototype.download = function(source, target, successCallback, erro
headers = options.headers || null;
}
+ if (cordova.platformId === "windowsphone" && headers) {
+ headers = convertHeadersToArray(headers);
+ }
+
var win = function(result) {
if (typeof result.lengthComputable != "undefined") {
if (self.onprogress) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[3/3] cordova-plugin-file-transfer git commit: fix failing test
resulting from overlapping async calls
Posted by pu...@apache.org.
fix failing test resulting from overlapping async calls
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/f1e41ac1
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/f1e41ac1
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/f1e41ac1
Branch: refs/heads/master
Commit: f1e41ac1f55b94e539b8e9346dfe1e6ffabb8aee
Parents: 65eea29
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Mon May 11 17:47:08 2015 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Mon May 11 17:47:08 2015 -0700
----------------------------------------------------------------------
src/wp/FileTransfer.cs | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/f1e41ac1/src/wp/FileTransfer.cs
----------------------------------------------------------------------
diff --git a/src/wp/FileTransfer.cs b/src/wp/FileTransfer.cs
index e9b3182..c74738e 100644
--- a/src/wp/FileTransfer.cs
+++ b/src/wp/FileTransfer.cs
@@ -377,6 +377,11 @@ namespace WPCordovaClassLib.Cordova.Commands
webRequest.ContentType = "multipart/form-data; boundary=" + Boundary;
webRequest.Method = uploadOptions.Method;
+ DownloadRequestState reqState = new DownloadRequestState();
+ InProcDownloads[uploadOptions.Id] = reqState;
+ reqState.options = uploadOptions;
+ reqState.request = webRequest;
+
// Associate cookies with the request
// This is an async call, so we need to await it in order to preserve proper control flow
await CopyCookiesFromWebBrowser(webRequest);
@@ -393,12 +398,6 @@ namespace WPCordovaClassLib.Cordova.Commands
}
}
- DownloadRequestState reqState = new DownloadRequestState();
- reqState.options = uploadOptions;
- reqState.request = webRequest;
-
- InProcDownloads[uploadOptions.Id] = reqState;
-
webRequest.BeginGetRequestStream(uploadCallback, reqState);
}
catch (Exception /*ex*/)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[2/3] cordova-plugin-file-transfer git commit: fix merge
Posted by pu...@apache.org.
fix merge
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/65eea291
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/65eea291
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/65eea291
Branch: refs/heads/master
Commit: 65eea291b291af2f44edb5c08c905ca66be68dd9
Parents: 3effd7f 21fb03a
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Fri May 8 17:23:17 2015 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Fri May 8 17:23:17 2015 -0700
----------------------------------------------------------------------
src/wp/FileTransfer.cs | 40 +++++++++++++++++-----------------------
www/FileTransfer.js | 23 +++++++++++++++++++++++
2 files changed, 40 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/65eea291/src/wp/FileTransfer.cs
----------------------------------------------------------------------
diff --cc src/wp/FileTransfer.cs
index 72f52fc,8e234cd..e9b3182
--- a/src/wp/FileTransfer.cs
+++ b/src/wp/FileTransfer.cs
@@@ -22,7 -22,7 +23,8 @@@ using System.Runtime.Serialization
using System.Windows;
using System.Security;
using System.Diagnostics;
+using System.Threading.Tasks;
+ using WPCordovaClassLib.Cordova.JSON;
namespace WPCordovaClassLib.Cordova.Commands
{
@@@ -216,79 -212,18 +218,91 @@@
}
/// <summary>
+ /// Represents a request header passed from Javascript to upload/download operations
+ /// </summary>
+ [DataContract]
+ protected struct Header
+ {
+ [DataMember(Name = "name")]
+ public string Name;
+
+ [DataMember(Name = "value")]
+ public string Value;
+ }
+
+ /// Helper method to copy all relevant cookies from the WebBrowser control into a header on
+ /// the HttpWebRequest
+ /// </summary>
+ /// <param name="browser">The source browser to copy the cookies from</param>
+ /// <param name="webRequest">The destination HttpWebRequest to add the cookie header to</param>
+ /// <returns>Nothing</returns>
+ private async Task CopyCookiesFromWebBrowser(HttpWebRequest webRequest)
+ {
+ var tcs = new TaskCompletionSource<object>();
+
+ // Accessing WebBrowser needs to happen on the UI thread
+ Deployment.Current.Dispatcher.BeginInvoke(() =>
+ {
+ // Get the WebBrowser control
+ if (this.browser == null)
+ {
+ PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame;
+ if (frame != null)
+ {
+ PhoneApplicationPage page = frame.Content as PhoneApplicationPage;
+ if (page != null)
+ {
+ CordovaView cView = page.FindName("CordovaView") as CordovaView;
+ if (cView != null)
+ {
+ this.browser = cView.Browser;
+ }
+ }
+ }
+ }
+
+ try
+ {
+ // Only copy the cookies if the scheme and host match (to avoid any issues with secure/insecure cookies)
+ // NOTE: since the returned CookieCollection appears to munge the original cookie's domain value in favor of the actual Source domain,
+ // we can't know for sure whether the cookies would be applicable to any other hosts, so best to play it safe and skip for now.
+ if (this.browser != null && this.browser.Source.IsAbsoluteUri == true &&
+ this.browser.Source.Scheme == webRequest.RequestUri.Scheme && this.browser.Source.Host == webRequest.RequestUri.Host)
+ {
+ string cookieHeader = "";
+ string requestPath = webRequest.RequestUri.PathAndQuery;
+ CookieCollection cookies = this.browser.GetCookies();
+
+ // Iterate over the cookies and add to the header
+ foreach (Cookie cookie in cookies)
+ {
+ // Check that the path is allowed, first
+ // NOTE: Path always seems to be empty for now, even if the cookie has a path set by the server.
+ if (cookie.Path.Length == 0 || requestPath.IndexOf(cookie.Path, StringComparison.InvariantCultureIgnoreCase) == 0)
+ {
+ cookieHeader += cookie.Name + "=" + cookie.Value + "; ";
+ }
+ }
+
+ // Finally, set the header if we found any cookies
+ if (cookieHeader.Length > 0)
+ {
+ webRequest.Headers["Cookie"] = cookieHeader;
+ }
+ }
+ }
+ catch (Exception)
+ {
+ // Swallow the exception
+ }
+
+ // Complete the task
+ tcs.SetResult(Type.Missing);
+ });
+
+ await tcs.Task;
+ }
+
/// <summary>
/// Upload options
/// </summary>
@@@ -425,10 -333,10 +419,10 @@@
{
Debug.WriteLine("Failed to parseHeaders from string :: " + jsonHeaders);
}
- return null;
+ return new Dictionary<string, string>();
}
- public void download(string options)
+ public async void download(string options)
{
TransferOptions downloadOptions = null;
HttpWebRequest webRequest = null;
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/65eea291/www/FileTransfer.js
----------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org