From c515f793e524b105875b78e654284c35531443a9 Mon Sep 17 00:00:00 2001 From: Luca Bacci Date: Tue, 20 Feb 2024 11:14:04 +0100 Subject: [PATCH 1/2] GWinHttpFile: Set display-name and type at the start of the query_info() function Those attributes do not need the HTTP(S) request data, so just set them right away. --- gio/win32/gwinhttpfile.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/gio/win32/gwinhttpfile.c b/gio/win32/gwinhttpfile.c index 408c2ade8..7a40a3335 100644 --- a/gio/win32/gwinhttpfile.c +++ b/gio/win32/gwinhttpfile.c @@ -477,6 +477,25 @@ g_winhttp_file_query_info (GFile *file, SYSTEMTIME last_modified; DWORD last_modified_len; + matcher = g_file_attribute_matcher_new (attributes); + info = g_file_info_new (); + g_file_info_set_attribute_mask (info, matcher); + + basename = g_winhttp_file_get_basename (file); + g_file_info_set_name (info, basename); + g_free (basename); + + if (_g_file_attribute_matcher_matches_id (matcher, + G_FILE_ATTRIBUTE_ID_STANDARD_DISPLAY_NAME)) + { + char *display_name = g_winhttp_file_get_display_name (file); + g_file_info_set_display_name (info, display_name); + g_free (display_name); + } + + if (_g_file_attribute_matcher_matches_id (matcher, G_FILE_ATTRIBUTE_ID_STANDARD_TYPE)) + g_file_info_set_file_type (info, G_FILE_TYPE_REGULAR); + connection = G_WINHTTP_VFS_GET_CLASS (winhttp_file->vfs)->funcs->pWinHttpConnect (G_WINHTTP_VFS (winhttp_file->vfs)->session, winhttp_file->url.lpszHostName, @@ -521,25 +540,6 @@ g_winhttp_file_query_info (GFile *file, if (!_g_winhttp_response (winhttp_file->vfs, request, error, "HEAD request")) return NULL; - matcher = g_file_attribute_matcher_new (attributes); - info = g_file_info_new (); - g_file_info_set_attribute_mask (info, matcher); - - basename = g_winhttp_file_get_basename (file); - g_file_info_set_name (info, basename); - g_free (basename); - - if (_g_file_attribute_matcher_matches_id (matcher, - G_FILE_ATTRIBUTE_ID_STANDARD_DISPLAY_NAME)) - { - char *display_name = g_winhttp_file_get_display_name (file); - g_file_info_set_display_name (info, display_name); - g_free (display_name); - } - - if (_g_file_attribute_matcher_matches_id (matcher, G_FILE_ATTRIBUTE_ID_STANDARD_TYPE)) - g_file_info_set_file_type (info, G_FILE_TYPE_REGULAR); - content_length = NULL; if (_g_winhttp_query_header (winhttp_file->vfs, request, From 4337f8f7351590ab4e95ca18d32f0e3416189df4 Mon Sep 17 00:00:00 2001 From: Luca Bacci Date: Tue, 20 Feb 2024 11:26:30 +0100 Subject: [PATCH 2/2] GWinHttpFile: Check for matching attributes before sending the HTTP(S) request We might not need to make an HTTP(S) request at all Fixes #3080 --- gio/win32/gwinhttpfile.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gio/win32/gwinhttpfile.c b/gio/win32/gwinhttpfile.c index 7a40a3335..605c28460 100644 --- a/gio/win32/gwinhttpfile.c +++ b/gio/win32/gwinhttpfile.c @@ -496,6 +496,15 @@ g_winhttp_file_query_info (GFile *file, if (_g_file_attribute_matcher_matches_id (matcher, G_FILE_ATTRIBUTE_ID_STANDARD_TYPE)) g_file_info_set_file_type (info, G_FILE_TYPE_REGULAR); + if (!(_g_file_attribute_matcher_matches_id (matcher, G_FILE_ATTRIBUTE_ID_STANDARD_SIZE) || + _g_file_attribute_matcher_matches_id (matcher, G_FILE_ATTRIBUTE_ID_STANDARD_CONTENT_TYPE) || + _g_file_attribute_matcher_matches_id (matcher, G_FILE_ATTRIBUTE_ID_TIME_MODIFIED) || + _g_file_attribute_matcher_matches_id (matcher, G_FILE_ATTRIBUTE_ID_TIME_MODIFIED_NSEC) || + _g_file_attribute_matcher_matches_id (matcher, G_FILE_ATTRIBUTE_ID_TIME_MODIFIED_USEC))) + { + return info; + } + connection = G_WINHTTP_VFS_GET_CLASS (winhttp_file->vfs)->funcs->pWinHttpConnect (G_WINHTTP_VFS (winhttp_file->vfs)->session, winhttp_file->url.lpszHostName,