diff options
author | Mario Sanchez Prada <msanchez@igalia.com> | 2009-10-02 12:33:02 +0200 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2009-12-17 10:31:53 +0100 |
commit | d15f6c4e50f361fe0be757437dbafe0aa5badc62 (patch) | |
tree | b7ba529ea58a0b247828a75f0e23b6059b439800 /libsoup/soup-session.c | |
parent | 9e7d41c707abed650df43dba9bcacce3703efe3c (diff) | |
download | libsoup-d15f6c4e50f361fe0be757437dbafe0aa5badc62.tar.gz |
Provide a new 'accept-language' property for SoupSession
This would allow to externally set a list of languages for the HTTP
"Accept-Language" header, compliant to rfc2616.
https://bugzilla.gnome.org/show_bug.cgi?id=597004
Diffstat (limited to 'libsoup/soup-session.c')
-rw-r--r-- | libsoup/soup-session.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c index b8d79a2b..48f336e3 100644 --- a/libsoup/soup-session.c +++ b/libsoup/soup-session.c @@ -75,6 +75,7 @@ typedef struct { SoupMessageQueue *queue; char *user_agent; + char *accept_language; GSList *features; GHashTable *features_cache; @@ -141,6 +142,7 @@ enum { PROP_ASYNC_CONTEXT, PROP_TIMEOUT, PROP_USER_AGENT, + PROP_ACCEPT_LANGUAGE, PROP_IDLE_TIMEOUT, PROP_ADD_FEATURE, PROP_ADD_FEATURE_BY_TYPE, @@ -216,6 +218,7 @@ finalize (GObject *object) g_hash_table_destroy (priv->conns); g_free (priv->user_agent); + g_free (priv->accept_language); if (priv->ssl_creds) soup_ssl_free_client_credentials (priv->ssl_creds); @@ -569,6 +572,26 @@ soup_session_class_init (SoupSessionClass *session_class) G_PARAM_READWRITE)); /** + * SoupSession:accept-language: + * + * If non-%NULL, the value to use for the "Accept-Language" header + * on #SoupMessage<!-- -->s sent from this session. + * + **/ + /** + * SOUP_SESSION_ACCEPT_LANGUAGE: + * + * Alias for the #SoupSession:accept-language property, qv. + **/ + g_object_class_install_property ( + object_class, PROP_ACCEPT_LANGUAGE, + g_param_spec_string (SOUP_SESSION_ACCEPT_LANGUAGE, + "Accept-Language string", + "Accept-Language string", + NULL, + G_PARAM_READWRITE)); + + /** * SoupSession:add-feature: * * Add a feature object to the session. (Shortcut for calling @@ -730,6 +753,10 @@ set_property (GObject *object, guint prop_id, } else priv->user_agent = g_strdup (user_agent); break; + case PROP_ACCEPT_LANGUAGE: + g_free (priv->accept_language); + priv->accept_language = g_strdup (g_value_get_string (value)); + break; case PROP_IDLE_TIMEOUT: priv->idle_timeout = g_value_get_uint (value); break; @@ -793,6 +820,9 @@ get_property (GObject *object, guint prop_id, case PROP_USER_AGENT: g_value_set_string (value, priv->user_agent); break; + case PROP_ACCEPT_LANGUAGE: + g_value_set_string (value, priv->accept_language); + break; case PROP_IDLE_TIMEOUT: g_value_set_uint (value, priv->idle_timeout); break; @@ -991,6 +1021,12 @@ soup_session_send_queue_item (SoupSession *session, "User-Agent", priv->user_agent); } + if (priv->accept_language) { + soup_message_headers_replace (item->msg->request_headers, + "Accept-Language", + priv->accept_language); + } + g_signal_emit (session, signals[REQUEST_STARTED], 0, item->msg, soup_connection_get_socket (conn)); soup_connection_send_request (conn, item->msg); |