diff options
author | Philip Withnall <pwithnall@endlessos.org> | 2020-09-24 17:49:48 +0100 |
---|---|---|
committer | Philip Withnall <pwithnall@endlessos.org> | 2020-10-22 21:03:34 +0100 |
commit | 407c683524bb362cbc39b8445015e4b06e5296a5 (patch) | |
tree | c6ac0bcc132862e8cab9277b2cb184d16c53e264 /src/libostree/ostree-fetcher-util.c | |
parent | 9f98aa922329757a538a4e76394779c2d5a24f23 (diff) | |
download | ostree-407c683524bb362cbc39b8445015e4b06e5296a5.tar.gz |
libostree: Add support for ETag and Last-Modified headers
Add support in the soup and curl fetchers to send the `If-None-Match`
and `If-Modified-Since` request headers, and pass on the `ETag` and
`Last-Modified` response headers.
This currently introduces no functional changes, but once call sites
provide the appropriate integration, this will allow HTTP caching to
happen with requests (typically with metadata requests, where the data
is not immutable due to being content-addressed). That should reduce
bandwidth requirements.
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Diffstat (limited to 'src/libostree/ostree-fetcher-util.c')
-rw-r--r-- | src/libostree/ostree-fetcher-util.c | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/src/libostree/ostree-fetcher-util.c b/src/libostree/ostree-fetcher-util.c index 1c3f8104..76f6bba1 100644 --- a/src/libostree/ostree-fetcher-util.c +++ b/src/libostree/ostree-fetcher-util.c @@ -34,6 +34,9 @@ typedef struct { GBytes *result_buf; + gboolean result_not_modified; + char *result_etag; + guint64 result_last_modified; /* second since the epoch */ gboolean done; GError **error; } @@ -48,6 +51,8 @@ fetch_uri_sync_on_complete (GObject *object, (void)_ostree_fetcher_request_to_membuf_finish ((OstreeFetcher*)object, result, &data->result_buf, + &data->result_not_modified, + &data->result_etag, &data->result_last_modified, data->error); data->done = TRUE; } @@ -57,7 +62,12 @@ _ostree_fetcher_mirrored_request_to_membuf_once (OstreeFetcher *fe GPtrArray *mirrorlist, const char *filename, OstreeFetcherRequestFlags flags, + const char *if_none_match, + guint64 if_modified_since, GBytes **out_contents, + gboolean *out_not_modified, + char **out_etag, + guint64 *out_last_modified, guint64 max_size, GCancellable *cancellable, GError **error) @@ -79,7 +89,7 @@ _ostree_fetcher_mirrored_request_to_membuf_once (OstreeFetcher *fe data.error = error; _ostree_fetcher_request_to_membuf (fetcher, mirrorlist, filename, - flags, + flags, if_none_match, if_modified_since, max_size, OSTREE_FETCHER_DEFAULT_PRIORITY, cancellable, fetch_uri_sync_on_complete, &data); while (!data.done) @@ -94,6 +104,12 @@ _ostree_fetcher_mirrored_request_to_membuf_once (OstreeFetcher *fe g_clear_error (error); ret = TRUE; *out_contents = NULL; + if (out_not_modified != NULL) + *out_not_modified = FALSE; + if (out_etag != NULL) + *out_etag = NULL; + if (out_last_modified != NULL) + *out_last_modified = 0; } } goto out; @@ -101,10 +117,17 @@ _ostree_fetcher_mirrored_request_to_membuf_once (OstreeFetcher *fe ret = TRUE; *out_contents = g_steal_pointer (&data.result_buf); + if (out_not_modified != NULL) + *out_not_modified = data.result_not_modified; + if (out_etag != NULL) + *out_etag = g_steal_pointer (&data.result_etag); + if (out_last_modified != NULL) + *out_last_modified = data.result_last_modified; out: if (mainctx) g_main_context_pop_thread_default (mainctx); g_clear_pointer (&data.result_buf, (GDestroyNotify)g_bytes_unref); + g_clear_pointer (&data.result_etag, g_free); return ret; } @@ -113,8 +136,13 @@ _ostree_fetcher_mirrored_request_to_membuf (OstreeFetcher *fetcher GPtrArray *mirrorlist, const char *filename, OstreeFetcherRequestFlags flags, + const char *if_none_match, + guint64 if_modified_since, guint n_network_retries, GBytes **out_contents, + gboolean *out_not_modified, + char **out_etag, + guint64 *out_last_modified, guint64 max_size, GCancellable *cancellable, GError **error) @@ -127,7 +155,9 @@ _ostree_fetcher_mirrored_request_to_membuf (OstreeFetcher *fetcher g_clear_error (&local_error); if (_ostree_fetcher_mirrored_request_to_membuf_once (fetcher, mirrorlist, filename, flags, - out_contents, max_size, + if_none_match, if_modified_since, + out_contents, out_not_modified, out_etag, + out_last_modified, max_size, cancellable, &local_error)) return TRUE; } @@ -143,8 +173,13 @@ gboolean _ostree_fetcher_request_uri_to_membuf (OstreeFetcher *fetcher, OstreeFetcherURI *uri, OstreeFetcherRequestFlags flags, + const char *if_none_match, + guint64 if_modified_since, guint n_network_retries, GBytes **out_contents, + gboolean *out_not_modified, + char **out_etag, + guint64 *out_last_modified, guint64 max_size, GCancellable *cancellable, GError **error) @@ -152,7 +187,9 @@ _ostree_fetcher_request_uri_to_membuf (OstreeFetcher *fetcher, g_autoptr(GPtrArray) mirrorlist = g_ptr_array_new (); g_ptr_array_add (mirrorlist, uri); /* no transfer */ return _ostree_fetcher_mirrored_request_to_membuf (fetcher, mirrorlist, NULL, flags, - n_network_retries, out_contents, max_size, + if_none_match, if_modified_since, + n_network_retries, out_contents, + out_not_modified, out_etag, out_last_modified, max_size, cancellable, error); } |