[evolution-data-server/wip/mcrha/soup3] ESoupSession: Error out on unsuccessful response from the server



commit e5188164d500854f50b13fc28ac06524f7f9a2c6
Author: Milan Crha <mcrha redhat com>
Date:   Tue May 31 15:56:36 2022 +0200

    ESoupSession: Error out on unsuccessful response from the server
    
    ... without returning message body.

 src/calendar/backends/http/e-cal-backend-http.c |  4 +++
 src/libedataserver/e-soup-session.c             | 35 +++++++++++--------------
 2 files changed, 19 insertions(+), 20 deletions(-)
---
diff --git a/src/calendar/backends/http/e-cal-backend-http.c b/src/calendar/backends/http/e-cal-backend-http.c
index 246334aa2..90b64cb07 100644
--- a/src/calendar/backends/http/e-cal-backend-http.c
+++ b/src/calendar/backends/http/e-cal-backend-http.c
@@ -246,6 +246,10 @@ ecb_http_connect_sync (ECalMetaBackend *meta_backend,
                if (success && !SOUP_STATUS_IS_SUCCESSFUL (soup_message_get_status (message)) && 
soup_message_get_status (message) != SOUP_STATUS_NOT_MODIFIED) {
                        g_clear_object (&input_stream);
                        success = FALSE;
+               } else if (g_error_matches (local_error, E_SOUP_SESSION_ERROR, SOUP_STATUS_NOT_MODIFIED)) {
+                       g_clear_object (&input_stream);
+                       g_clear_error (&local_error);
+                       success = TRUE;
                }
 
                if (success) {
diff --git a/src/libedataserver/e-soup-session.c b/src/libedataserver/e-soup-session.c
index e6edf7cb0..ef2843203 100644
--- a/src/libedataserver/e-soup-session.c
+++ b/src/libedataserver/e-soup-session.c
@@ -1199,6 +1199,7 @@ e_soup_session_send_message_ready_cb (GObject *source_object,
        AsyncSendData *asd = user_data;
        ESoupSession *esession;
        SoupSession *session;
+       SoupMessage *message;
        GInputStream *input_stream;
        GError *local_error = NULL;
 
@@ -1210,21 +1211,16 @@ e_soup_session_send_message_ready_cb (GObject *source_object,
        g_rec_mutex_lock (&esession->priv->session_lock);
 
        input_stream = soup_session_send_finish (session, result, &local_error);
+       message = soup_session_get_async_result_message (session, result);
 
-       if (!input_stream) {
-               SoupMessage *message;
-
-               message = soup_session_get_async_result_message (session, result);
-
-               if (message) {
-                       if (g_error_matches (local_error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE)) {
-                               e_soup_session_extract_ssl_data (E_SOUP_SESSION (session), message, 
&asd->certificate_pem, &asd->certificate_errors);
-                       } else if (!local_error) {
-                               if (soup_message_get_status (message) != SOUP_STATUS_FORBIDDEN ||
-                                   !e_soup_session_extract_google_daily_limit_error (NULL, 0, &local_error))
-                                       g_set_error_literal (&local_error, E_SOUP_SESSION_ERROR, 
soup_message_get_status (message),
-                                               soup_message_get_reason_phrase (message));
-                       }
+       if (message) {
+               if (g_error_matches (local_error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE)) {
+                       e_soup_session_extract_ssl_data (E_SOUP_SESSION (session), message, 
&asd->certificate_pem, &asd->certificate_errors);
+               } else if (!local_error && !SOUP_STATUS_IS_SUCCESSFUL (soup_message_get_status (message))) {
+                       if (soup_message_get_status (message) != SOUP_STATUS_FORBIDDEN ||
+                           !e_soup_session_extract_google_daily_limit_error (NULL, 0, &local_error))
+                               g_set_error_literal (&local_error, E_SOUP_SESSION_ERROR, 
soup_message_get_status (message),
+                                       soup_message_get_reason_phrase (message));
                }
        }
 
@@ -1457,22 +1453,21 @@ e_soup_session_send_message_sync (ESoupSession *session,
        if (restarted_id)
                g_signal_handler_disconnect (message, restarted_id);
 
-       if (input_stream)
-               return input_stream;
-
        if (g_error_matches (local_error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE)) {
                e_soup_session_extract_ssl_data_internal (session, message);
-       } else if (!local_error) {
+       } else if (!local_error && !SOUP_STATUS_IS_SUCCESSFUL (soup_message_get_status (message))) {
                if (soup_message_get_status (message) != SOUP_STATUS_FORBIDDEN ||
                    !e_soup_session_extract_google_daily_limit_error (NULL, 0, error))
                        g_set_error_literal (&local_error, E_SOUP_SESSION_ERROR, soup_message_get_status 
(message),
                                soup_message_get_reason_phrase (message));
        }
 
-       if (local_error)
+       if (local_error) {
                g_propagate_error (error, local_error);
+               g_clear_object (&input_stream);
+       }
 
-       return NULL;
+       return input_stream;
 }
 
 /**


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