[evolution-data-server/gnome-3-26] Bug 787935 - Handle Redirection in ESoupSession



commit b63376f7d8daa12033e5c3e3136f1c0407cf27c3
Author: Milan Crha <mcrha redhat com>
Date:   Thu Sep 21 12:03:49 2017 +0200

    Bug 787935 - Handle Redirection in ESoupSession

 src/libedataserver/e-soup-session.c   |   41 ++++++++++++++++++++++++++++++++-
 src/libedataserver/e-webdav-session.c |    2 +
 2 files changed, 42 insertions(+), 1 deletions(-)
---
diff --git a/src/libedataserver/e-soup-session.c b/src/libedataserver/e-soup-session.c
index 8e71b85..b247fb5 100644
--- a/src/libedataserver/e-soup-session.c
+++ b/src/libedataserver/e-soup-session.c
@@ -896,6 +896,8 @@ e_soup_session_send_request_sync (ESoupSession *session,
        ESoupAuthBearer *using_bearer_auth = NULL;
        GInputStream *input_stream;
        SoupMessage *message;
+       gboolean redirected;
+       gint resend_count = 0;
        GError *local_error = NULL;
 
        g_return_val_if_fail (E_IS_SOUP_SESSION (session), NULL);
@@ -944,7 +946,44 @@ e_soup_session_send_request_sync (ESoupSession *session,
 
        g_clear_object (&using_bearer_auth);
 
-       input_stream = soup_request_send (SOUP_REQUEST (request), cancellable, &local_error);
+       redirected = TRUE;
+       while (redirected) {
+               redirected = FALSE;
+
+               input_stream = soup_request_send (SOUP_REQUEST (request), cancellable, &local_error);
+               if (input_stream) {
+                       message = soup_request_http_get_message (request);
+
+                       if (message && SOUP_STATUS_IS_REDIRECTION (message->status_code)) {
+                               /* libsoup uses 20, but the constant is not in any public header */
+                               if (resend_count >= 30) {
+                                       soup_message_set_status (message, SOUP_STATUS_TOO_MANY_REDIRECTS);
+                               } else {
+                                       const gchar *new_location;
+
+                                       new_location = soup_message_headers_get_list 
(message->response_headers, "Location");
+                                       if (new_location) {
+                                               SoupURI *new_uri;
+
+                                               new_uri = soup_uri_new_with_base (soup_message_get_uri 
(message), new_location);
+
+                                               soup_message_set_uri (message, new_uri);
+
+                                               g_clear_object (&input_stream);
+                                               soup_uri_free (new_uri);
+
+                                               g_signal_emit_by_name (message, "restarted");
+
+                                               resend_count++;
+                                               redirected = TRUE;
+                                       }
+                               }
+                       }
+
+                       g_clear_object (&message);
+               }
+       }
+
        if (input_stream)
                return input_stream;
 
diff --git a/src/libedataserver/e-webdav-session.c b/src/libedataserver/e-webdav-session.c
index 281da4c..2b9281a 100644
--- a/src/libedataserver/e-webdav-session.c
+++ b/src/libedataserver/e-webdav-session.c
@@ -2136,6 +2136,8 @@ e_webdav_session_write_restarted (SoupMessage *message,
                                        _("Cannot rewind input stream: Not supported"));
 
                        soup_session_cancel_message (cwd->session, message, SOUP_STATUS_CANCELLED);
+               } else {
+                       soup_message_body_truncate (message->request_body);
                }
        }
 }


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