diff options
author | Lucas Chollet <lucas.chollet@free.fr> | 2023-02-06 14:29:08 -0500 |
---|---|---|
committer | Ondrej Holy <oholy@redhat.com> | 2023-02-08 09:07:37 +0000 |
commit | 4b95657e236f49bb7b9416230d69673fee57d4f8 (patch) | |
tree | 473eed005714a682e1a05c4e16349faa79e22813 | |
parent | a70e9fbdf34768985925b2b81661190a094e718b (diff) | |
download | gvfs-4b95657e236f49bb7b9416230d69673fee57d4f8.tar.gz |
http: Fill `GFileInfo` with uncompressed sizes
Currently, using `FileProgressCallback` is quite confusing as
`current_num_bytes` is in uncompressed bytes unlike `total_num_bytes`
which is in compressed bytes.
In order to solve this issue, we disable compression in `query_info` by
setting the "Accept-Encoding" flag to `identity` (none). Then whenever
`query_info_on_read` is called, we make sure that the request wasn't set
to accept compresssion and fallback to `query_info` if it is the case.
Fixes #195
-rw-r--r-- | daemon/gvfsbackendhttp.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/daemon/gvfsbackendhttp.c b/daemon/gvfsbackendhttp.c index e8e44004..f86e468d 100644 --- a/daemon/gvfsbackendhttp.c +++ b/daemon/gvfsbackendhttp.c @@ -706,6 +706,10 @@ try_query_info (GVfsBackend *backend, uri = http_backend_get_mount_base (backend); msg = soup_message_new_from_uri (SOUP_METHOD_HEAD, uri); + /* Disable encoding in order to retrieve the size of the full file. */ + soup_message_headers_replace (soup_message_get_request_headers (msg), + "Accept-Encoding", "identity"); + g_vfs_job_set_backend_data (G_VFS_JOB (job), msg, NULL); soup_session_send_async (op_backend->session, msg, G_PRIORITY_DEFAULT, @@ -724,6 +728,25 @@ try_query_info_on_read (GVfsBackend *backend, { SoupMessage *msg = g_vfs_http_input_stream_get_message (G_INPUT_STREAM (handle)); + const gchar *encoding; + + /* In case encoding is set, Content-Length will report the compressed size, + * but we want to report the complete size of the file to the user. This + * will cause try_query_info() to be invoked, hence reporting the size + * without compression enabled. + */ + encoding = soup_message_headers_get_one (soup_message_get_response_headers (msg), + "Content-Encoding"); + if (encoding != NULL && + g_file_attribute_matcher_matches (attribute_matcher, G_FILE_ATTRIBUTE_STANDARD_SIZE)) + { + g_vfs_job_failed_literal (G_VFS_JOB (job), G_IO_ERROR, + G_IO_ERROR_NOT_SUPPORTED, + _("Operation not supported")); + g_object_unref (msg); + return TRUE; + } + file_info_from_message (msg, info, attribute_matcher); g_object_unref (msg); |