Commit 60213316 authored by Milan Crha's avatar Milan Crha

[EHTTPRequest] Immediately cancel ongoing download on request cancel

No need to continue any download when the request had been cancelled.
This could cause starving of other requests with download of large images.
parent bad53279
......@@ -155,6 +155,13 @@ send_and_handle_redirection (SoupSession *session,
g_free (old_uri);
static void
http_request_cancelled_cb (GCancellable *cancellable,
SoupSession *session)
soup_session_abort (session);
static void
handle_http_request (GSimpleAsyncResult *res,
GObject *source_object,
......@@ -360,6 +367,10 @@ handle_http_request (GSimpleAsyncResult *res,
GIOStream *cache_stream;
GError *error;
GMainContext *context;
gulong cancelled_id = 0;
if (g_cancellable_is_cancelled (cancellable))
goto cleanup;
message = soup_message_new (SOUP_METHOD_GET, uri);
if (!message) {
......@@ -382,8 +393,14 @@ handle_http_request (GSimpleAsyncResult *res,
"User-Agent", "Evolution/" VERSION);
if (cancellable)
cancelled_id = g_cancellable_connect (cancellable, G_CALLBACK (http_request_cancelled_cb), temp_session, NULL);
send_and_handle_redirection (temp_session, message, NULL);
if (cancellable && cancelled_id)
g_cancellable_disconnect (cancellable, cancelled_id);
if (!SOUP_STATUS_IS_SUCCESSFUL (message->status_code)) {
g_debug ("Failed to request %s (code %d)", uri, message->status_code);
g_object_unref (message);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment