summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergio Villar Senin <svillar@igalia.com>2011-01-28 17:32:23 -0500
committerDan Winship <danw@gnome.org>2011-01-28 17:33:40 -0500
commitd88ee37535aa80635c5be4f9089e43b7c15ea8c9 (patch)
tree3e1fc948c240bb867129a9d2f190517cc1aa55a9
parent6a0eae72b5c6b76fb1d77fcf4c7c26a7598ae6aa (diff)
downloadlibsoup-d88ee37535aa80635c5be4f9089e43b7c15ea8c9.tar.gz
SoupCache fails to load resources when cache contents are externally removed
Try to download cached resources again if they are no longer accesible by the cache. https://bugs.webkit.org/show_bug.cgi?id=50577 (belatedly copied from WebKit's version of this file)
-rw-r--r--libsoup/soup-request-http.c71
1 files changed, 38 insertions, 33 deletions
diff --git a/libsoup/soup-request-http.c b/libsoup/soup-request-http.c
index 81e59df1..42cc6e01 100644
--- a/libsoup/soup-request-http.c
+++ b/libsoup/soup-request-http.c
@@ -171,6 +171,7 @@ typedef struct {
SoupRequestHTTP *http;
GAsyncReadyCallback callback;
gpointer user_data;
+ SoupHTTPInputStream *httpstream;
} SendAsyncHelper;
static void soup_request_http_send_async (SoupRequest *request,
@@ -182,39 +183,32 @@ static gboolean
send_async_cb (gpointer data)
{
GSimpleAsyncResult *simple;
- SoupHTTPInputStream *httpstream;
SoupSession *session;
- SoupCache *cache;
SendAsyncHelper *helper = (SendAsyncHelper *)data;
session = soup_request_get_session (SOUP_REQUEST (helper->http));
- cache = (SoupCache *)soup_session_get_feature (session, SOUP_TYPE_CACHE);
-
- httpstream = (SoupHTTPInputStream *)soup_cache_send_response (cache, SOUP_MESSAGE (helper->http->priv->msg));
+ simple = g_simple_async_result_new (G_OBJECT (helper->http),
+ helper->callback, helper->user_data,
+ soup_request_http_send_async);
- if (httpstream) {
- simple = g_simple_async_result_new (G_OBJECT (helper->http),
- helper->callback, helper->user_data,
- soup_request_http_send_async);
- g_simple_async_result_set_op_res_gpointer (simple, httpstream, g_object_unref);
+ g_simple_async_result_set_op_res_gpointer (simple, helper->httpstream, g_object_unref);
- /* Update message status */
- soup_message_set_status (helper->http->priv->msg, SOUP_STATUS_OK);
+ /* Update message status */
+ soup_message_set_status (helper->http->priv->msg, SOUP_STATUS_OK);
- /* Issue signals */
- soup_message_got_headers (helper->http->priv->msg);
+ /* Issue signals */
+ soup_message_got_headers (helper->http->priv->msg);
- if (soup_session_get_feature_for_message (session, SOUP_TYPE_CONTENT_SNIFFER, helper->http->priv->msg)) {
- const char *content_type = soup_message_headers_get_content_type (helper->http->priv->msg->response_headers, NULL);
- soup_message_content_sniffed (helper->http->priv->msg, content_type, NULL);
- }
+ if (soup_session_get_feature_for_message (session, SOUP_TYPE_CONTENT_SNIFFER, helper->http->priv->msg)) {
+ const char *content_type = soup_message_headers_get_content_type (helper->http->priv->msg->response_headers, NULL);
+ soup_message_content_sniffed (helper->http->priv->msg, content_type, NULL);
+ }
- g_simple_async_result_complete (simple);
+ g_simple_async_result_complete (simple);
- soup_message_finished (helper->http->priv->msg);
+ soup_message_finished (helper->http->priv->msg);
- g_object_unref (simple);
- }
+ g_object_unref (simple);
g_object_unref (helper->http);
g_slice_free (SendAsyncHelper, helper);
@@ -242,17 +236,28 @@ soup_request_http_send_async (SoupRequest *request,
response = soup_cache_has_response (cache, http->priv->msg);
if (response == SOUP_CACHE_RESPONSE_FRESH) {
- /* Do return the stream asynchronously as in
- the other cases. It's not enough to use
- g_simple_async_result_complete_in_idle as
- the signals must be also emitted
- asynchronously */
- SendAsyncHelper *helper = g_slice_new (SendAsyncHelper);
- helper->http = g_object_ref (http);
- helper->callback = callback;
- helper->user_data = user_data;
- g_timeout_add (0, send_async_cb, helper);
- return;
+ SoupHTTPInputStream *httpstream;
+
+ httpstream = (SoupHTTPInputStream *)
+ soup_cache_send_response (cache, http->priv->msg);
+
+ /* Cached resource file could have been deleted outside
+ */
+ if (httpstream) {
+ /* Do return the stream asynchronously as in
+ * the other cases. It's not enough to use
+ * g_simple_async_result_complete_in_idle as
+ * the signals must be also emitted
+ * asynchronously
+ */
+ SendAsyncHelper *helper = g_slice_new (SendAsyncHelper);
+ helper->http = g_object_ref (http);
+ helper->callback = callback;
+ helper->user_data = user_data;
+ helper->httpstream = httpstream;
+ g_timeout_add (0, send_async_cb, helper);
+ return;
+ }
} else if (response == SOUP_CACHE_RESPONSE_NEEDS_VALIDATION) {
SoupMessage *conditional_msg;
ConditionalHelper *helper;