SoupCache and soup_session_send usage



Hey list,

I am using libsoup to download large video files, the download may
happen multiple times so I am using SoupCache to save them locally.

This works great if I use soup_session_send_async, however
soup_session_send doesn't seem to query the cache? soup_session_send is
used by GStreamer, so I am looking for the best way to get caching
working into GStreamer (and maybe help some others along the way)

soup_session_send_async manually queries here [0] however I don't see an
equivalent check in the implementation of soup_session_send does anyone
know if this was done on purpose? Would a patch be accepted if I added a
cache check to the soup_session_send?

thanks

[0] https://github.com/GNOME/libsoup/blob/master/libsoup/soup-session.c#L4300
----
Here is a working version below of soup_session_send_async if anyone
else wants to check. This isn't meant to be pretty, just an easy minimal
reproduce.

```
#include <libsoup/soup.h>
#include <stdlib.h>

static SoupCache *diskcache = NULL;

static void answer_finish(SoupSession *soup_session, GAsyncResult *result, gpointer user_data) {
    GInputStream *input_stream;
    input_stream = soup_session_send_finish(soup_session, result, NULL);

    void *c = g_malloc(100000);
    GError * error = NULL;

    while (TRUE) {
            ssize_t ret = g_input_stream_read(input_stream, c, 100000, NULL, &error);
            if (ret == 0) {
                    g_printerr ("g_input_stream_read: EOF\n");
                    break;
            } else if (error != NULL) {
                    g_printerr ("g_input_stream_read failed: %s\n", error->message);
                    break;
            }
            g_print ("read: %d\n", ret);
    }

    soup_cache_flush(diskcache);
    soup_cache_dump(diskcache);

    exit(1);
}

int main(void) {
        GMainLoop *loop = g_main_loop_new(NULL, FALSE);

        SoupSession *session = soup_session_new();
        SoupMessage *msg = NULL;

        diskcache = soup_cache_new("/tmp/soup-cache", SOUP_CACHE_SINGLE_USER);
        soup_cache_set_max_size(diskcache, 50000000);
        soup_cache_load(diskcache);
        soup_session_add_feature(session, SOUP_SESSION_FEATURE(diskcache));

        SoupLogger *logger = soup_logger_new(SOUP_LOGGER_LOG_HEADERS, 0);
        soup_session_add_feature(session, SOUP_SESSION_FEATURE(logger));

        msg = soup_message_new("GET", "http://localhost/cached-hit";);

        soup_session_send_async(session, msg, NULL, answer_finish, NULL);

        g_main_loop_run(loop);
}
```


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