[libgdata/wip/oholy/authorization-errors] core: Always refresh authorization when creating streams



commit 028b64f3256aefdde8860f3597718990114b9687
Author: Ondrej Holy <oholy redhat com>
Date:   Mon Jan 20 13:51:20 2020 +0100

    core: Always refresh authorization when creating streams
    
    Non-resumable upload streams quite often fail with authorization errors
    as we are probably hitting some limits. The only way currently to deal
    with them is to refresh authorization manually and upload everything
    again as it is not possible to resume the transfer. This is big issue
    for streaming operations provided by GVfs. I have made several tests
    and realized that if we explicitely refresh the authorization before
    the transfer, then those authorization errors doesn't occur. So let's
    always refresh the authorization when constructing the streams and do
    the same for upload streams as well as they are also affected. In theory,
    the resumable streams could solve this better, however they currently
    require content size to be specified at the beginning, which is not
    usable for the streaming operations in GVfs.
    
    Fixes: https://gitlab.gnome.org/GNOME/libgdata/issues/23

 gdata/gdata-download-stream.c | 7 +++++++
 gdata/gdata-upload-stream.c   | 7 +++++++
 2 files changed, 14 insertions(+)
---
diff --git a/gdata/gdata-download-stream.c b/gdata/gdata-download-stream.c
index 5bfd7048..4a1c109b 100644
--- a/gdata/gdata-download-stream.c
+++ b/gdata/gdata-download-stream.c
@@ -337,6 +337,7 @@ gdata_download_stream_constructor (GType type, guint n_construct_params, GObject
 {
        GDataDownloadStreamPrivate *priv;
        GDataServiceClass *klass;
+       GDataAuthorizer *authorizer;
        GObject *object;
        SoupURI *_uri;
 
@@ -355,6 +356,12 @@ gdata_download_stream_constructor (GType type, guint n_construct_params, GObject
                priv->cancellable = g_cancellable_new ();
        priv->network_cancellable_id = g_cancellable_connect (priv->cancellable, (GCallback) 
cancellable_cancel_cb, priv->network_cancellable, NULL);
 
+       /* Refresh authorization before building message in order to prevent authorization errors during 
transfer.
+        * See: https://gitlab.gnome.org/GNOME/libgdata/issues/23 */
+       authorizer = gdata_service_get_authorizer (priv->service);
+       if (authorizer)
+               gdata_authorizer_refresh_authorization (authorizer, priv->cancellable, NULL);
+
        /* Build the message. The URI must be HTTPS. */
        _uri = soup_uri_new (priv->download_uri);
        soup_uri_set_port (_uri, _gdata_service_get_https_port ());
diff --git a/gdata/gdata-upload-stream.c b/gdata/gdata-upload-stream.c
index 85807fec..be8c7f25 100644
--- a/gdata/gdata-upload-stream.c
+++ b/gdata/gdata-upload-stream.c
@@ -428,6 +428,7 @@ gdata_upload_stream_constructed (GObject *object)
 {
        GDataUploadStreamPrivate *priv;
        GDataServiceClass *service_klass;
+       GDataAuthorizer *authorizer;
        SoupURI *uri = NULL;
 
        /* Chain up to the parent class */
@@ -443,6 +444,12 @@ gdata_upload_stream_constructed (GObject *object)
        if (priv->cancellable == NULL)
                priv->cancellable = g_cancellable_new ();
 
+       /* Refresh authorization before building message in order to prevent authorization errors during 
transfer.
+        * See: https://gitlab.gnome.org/GNOME/libgdata/issues/23 */
+       authorizer = gdata_service_get_authorizer (priv->service);
+       if (authorizer)
+               gdata_authorizer_refresh_authorization (authorizer, priv->cancellable, NULL);
+
        /* Build the message */
        priv->message = build_message (GDATA_UPLOAD_STREAM (object), priv->method, priv->upload_uri);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]