utils/source-discoverer: Set the User-Agent
This avoids some web servers or WAFs doing weird stuff with our requests which would lead to situations where our web calendar source discovery would face server errors, redirects, incorrect contents, etc. Fixes #651 Fixes https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/290
This commit is contained in:
@@ -281,7 +281,7 @@ discover_file_in_thread (DiscovererData *data,
|
||||
uri_str = g_uri_to_string_partial (guri, G_URI_HIDE_PASSWORD);
|
||||
GCAL_TRACE_MSG ("Creating request for %s", uri_str);
|
||||
|
||||
session = soup_session_new_with_options ("timeout", 10, NULL);
|
||||
session = gcal_create_soup_session ();
|
||||
|
||||
message = soup_message_new_from_uri ("GET", guri);
|
||||
g_signal_connect (message, "authenticate", G_CALLBACK (on_soup_message_authenticate_cb), data);
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
#include <libecal/libecal.h>
|
||||
#include <libedataserver/libedataserver.h>
|
||||
#include <libsoup/soup.h>
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
@@ -1329,3 +1330,29 @@ gcal_get_service_name_from_url (const gchar *url)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* gcal_create_soup_session:
|
||||
*
|
||||
* Creates a new #SoupSession with correct default settings.
|
||||
*
|
||||
* Returns: (transfer full): a new #SoupSession
|
||||
*/
|
||||
SoupSession *
|
||||
gcal_create_soup_session (void)
|
||||
{
|
||||
g_autoptr (SoupSession) session = NULL;
|
||||
|
||||
session = soup_session_new ();
|
||||
|
||||
/* Set up a 10 seconds default timeout, as 60 is too long for fail-fast performance in general.
|
||||
* Individual parts of the code can always override this if needed. */
|
||||
soup_session_set_timeout (session, 10);
|
||||
|
||||
/* RFC2616 states HTTP requests "should" contain the User-Agent header. In practice though, in our situation
|
||||
* User-Agent is mandatory, or restrictive "web application firewalls" can do unexpected things with our request.
|
||||
* The trailing " - " lets libsoup append its name and version for us. */
|
||||
soup_session_set_user_agent (session, "GNOME Calendar/" PACKAGE_VERSION " - ");
|
||||
|
||||
return g_steal_pointer (&session);
|
||||
}
|
||||
|
||||
@@ -139,4 +139,6 @@ gboolean gcal_is_valid_event_name (const gchar
|
||||
|
||||
const gchar* gcal_get_service_name_from_url (const gchar *url);
|
||||
|
||||
SoupSession * gcal_create_soup_session (void);
|
||||
|
||||
#endif /* __GCAL_UTILS_H__ */
|
||||
|
||||
Reference in New Issue
Block a user