cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vladimir-kotikov <...@git.apache.org>
Subject [GitHub] cordova-plugin-file-transfer pull request: CB-8761 [wp8]: Copy coo...
Date Fri, 24 Apr 2015 09:40:14 GMT
Github user vladimir-kotikov commented on a diff in the pull request:

    https://github.com/apache/cordova-plugin-file-transfer/pull/74#discussion_r29036352
  
    --- Diff: src/wp/FileTransfer.cs ---
    @@ -210,6 +216,77 @@ public FileTransferProgress(long bTotal = 0, long bLoaded = 0)
             }
     
             /// <summary>
    +        /// 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.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)
== 0)
    +                            {
    +                                cookieHeader += cookie.Name + "=" + cookie.Value + ";
";
    +                            }
    +                        }
    +
    +                        // Finally, set the header if we found any cookies
    +                        if (cookieHeader.Length > 0)
    +                        {
    +                            webRequest.Headers["Cookie"] = cookieHeader;
    +                        }
    +                    }
    +                    tcs.SetResult(Type.Missing);
    +                }
    +                catch (Exception ex)
    +                {
    +                    tcs.SetException(ex);
    --- End diff --
    
    This exception will never be caught. Consider silently return from this method here or
add try/catch block around this method call in `upload` and `download`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


Mime
View raw message