1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
5 * Copyright (C) 2000-2003, Ximian, Inc.
16 #include "soup-auth.h"
17 #include "soup-session.h"
18 #include "soup-connection.h"
19 #include "soup-connection-ntlm.h"
20 #include "soup-marshal.h"
21 #include "soup-message-queue.h"
29 GSList *connections; /* CONTAINS: SoupConnection */
32 GHashTable *auth_realms; /* path -> scheme:realm */
33 GHashTable *auths; /* scheme:realm -> SoupAuth */
36 struct SoupSessionPrivate {
38 guint max_conns, max_conns_per_host;
44 SoupMessageQueue *queue;
46 GHashTable *hosts; /* SoupUri -> SoupSessionHost */
47 GHashTable *conns; /* SoupConnection -> SoupSessionHost */
50 SoupSessionHost *proxy_host;
53 static guint host_uri_hash (gconstpointer key);
54 static gboolean host_uri_equal (gconstpointer v1, gconstpointer v2);
55 static void free_host (SoupSessionHost *host, SoupSession *session);
57 static gboolean run_queue (SoupSession *session, gboolean try_pruning);
59 #define SOUP_SESSION_MAX_CONNS_DEFAULT 10
60 #define SOUP_SESSION_MAX_CONNS_PER_HOST_DEFAULT 4
62 #define PARENT_TYPE G_TYPE_OBJECT
63 static GObjectClass *parent_class;
71 static guint signals[LAST_SIGNAL] = { 0 };
78 PROP_MAX_CONNS_PER_HOST,
85 static void set_property (GObject *object, guint prop_id,
86 const GValue *value, GParamSpec *pspec);
87 static void get_property (GObject *object, guint prop_id,
88 GValue *value, GParamSpec *pspec);
91 init (GObject *object)
93 SoupSession *session = SOUP_SESSION (object);
95 session->priv = g_new0 (SoupSessionPrivate, 1);
96 session->priv->queue = soup_message_queue_new ();
97 session->priv->hosts = g_hash_table_new (host_uri_hash,
99 session->priv->conns = g_hash_table_new (NULL, NULL);
101 session->priv->max_conns = SOUP_SESSION_MAX_CONNS_DEFAULT;
102 session->priv->max_conns_per_host = SOUP_SESSION_MAX_CONNS_PER_HOST_DEFAULT;
106 foreach_free_host (gpointer key, gpointer host, gpointer session)
108 free_host (host, session);
113 cleanup_hosts (SoupSession *session)
115 g_hash_table_foreach_remove (session->priv->hosts,
116 foreach_free_host, session);
120 dispose (GObject *object)
122 SoupSession *session = SOUP_SESSION (object);
124 soup_session_abort (session);
125 cleanup_hosts (session);
127 G_OBJECT_CLASS (parent_class)->dispose (object);
131 finalize (GObject *object)
133 SoupSession *session = SOUP_SESSION (object);
135 soup_message_queue_destroy (session->priv->queue);
136 g_hash_table_destroy (session->priv->hosts);
137 g_hash_table_destroy (session->priv->conns);
138 g_free (session->priv);
140 G_OBJECT_CLASS (parent_class)->finalize (object);
144 class_init (GObjectClass *object_class)
146 parent_class = g_type_class_ref (PARENT_TYPE);
148 /* virtual method override */
149 object_class->dispose = dispose;
150 object_class->finalize = finalize;
151 object_class->set_property = set_property;
152 object_class->get_property = get_property;
155 signals[AUTHENTICATE] =
156 g_signal_new ("authenticate",
157 G_OBJECT_CLASS_TYPE (object_class),
159 G_STRUCT_OFFSET (SoupSessionClass, authenticate),
161 soup_marshal_NONE__OBJECT_STRING_STRING_POINTER_POINTER,
168 signals[REAUTHENTICATE] =
169 g_signal_new ("reauthenticate",
170 G_OBJECT_CLASS_TYPE (object_class),
172 G_STRUCT_OFFSET (SoupSessionClass, reauthenticate),
174 soup_marshal_NONE__OBJECT_STRING_STRING_POINTER_POINTER,
183 g_object_class_install_property (
184 object_class, PROP_PROXY_URI,
185 g_param_spec_pointer (SOUP_SESSION_PROXY_URI,
187 "The HTTP Proxy to use for this session",
189 g_object_class_install_property (
190 object_class, PROP_MAX_CONNS,
191 g_param_spec_int (SOUP_SESSION_MAX_CONNS,
192 "Max Connection Count",
193 "The maximum number of connections that the session can open at once",
198 g_object_class_install_property (
199 object_class, PROP_MAX_CONNS_PER_HOST,
200 g_param_spec_int (SOUP_SESSION_MAX_CONNS_PER_HOST,
201 "Max Per-Host Connection Count",
202 "The maximum number of connections that the session can open at once to a given host",
207 g_object_class_install_property (
208 object_class, PROP_USE_NTLM,
209 g_param_spec_boolean (SOUP_SESSION_USE_NTLM,
211 "Whether or not to use NTLM authentication",
214 g_object_class_install_property (
215 object_class, PROP_SSL_CA_FILE,
216 g_param_spec_string (SOUP_SESSION_SSL_CA_FILE,
218 "File containing SSL CA certificates",
223 SOUP_MAKE_TYPE (soup_session, SoupSession, class_init, init, PARENT_TYPE)
226 soup_session_new (void)
228 return g_object_new (SOUP_TYPE_SESSION, NULL);
232 soup_session_new_with_options (const char *optname1, ...)
234 SoupSession *session;
237 va_start (ap, optname1);
238 session = (SoupSession *)g_object_new_valist (SOUP_TYPE_SESSION, optname1, ap);
245 safe_uri_equal (const SoupUri *a, const SoupUri *b)
250 if (a && !b || b && !a)
253 return soup_uri_equal (a, b);
257 set_property (GObject *object, guint prop_id,
258 const GValue *value, GParamSpec *pspec)
260 SoupSession *session = SOUP_SESSION (object);
262 gboolean need_abort = FALSE;
266 pval = g_value_get_pointer (value);
268 if (!safe_uri_equal (session->priv->proxy_uri, pval))
271 if (session->priv->proxy_uri)
272 soup_uri_free (session->priv->proxy_uri);
274 session->priv->proxy_uri = pval ? soup_uri_copy (pval) : NULL;
277 soup_session_abort (session);
278 cleanup_hosts (session);
283 session->priv->max_conns = g_value_get_int (value);
285 case PROP_MAX_CONNS_PER_HOST:
286 session->priv->max_conns_per_host = g_value_get_int (value);
289 session->priv->use_ntlm = g_value_get_boolean (value);
291 case PROP_SSL_CA_FILE:
292 g_free (session->priv->ssl_ca_file);
293 session->priv->ssl_ca_file = g_strdup (g_value_get_string (value));
301 get_property (GObject *object, guint prop_id,
302 GValue *value, GParamSpec *pspec)
304 SoupSession *session = SOUP_SESSION (object);
308 g_value_set_pointer (value, session->priv->proxy_uri ?
309 soup_uri_copy (session->priv->proxy_uri) :
313 g_value_set_int (value, session->priv->max_conns);
315 case PROP_MAX_CONNS_PER_HOST:
316 g_value_set_int (value, session->priv->max_conns_per_host);
319 g_value_set_boolean (value, session->priv->use_ntlm);
321 case PROP_SSL_CA_FILE:
322 g_value_set_string (value, session->priv->ssl_ca_file);
332 host_uri_hash (gconstpointer key)
334 const SoupUri *uri = key;
336 return (uri->protocol << 16) + uri->port + g_str_hash (uri->host);
340 host_uri_equal (gconstpointer v1, gconstpointer v2)
342 const SoupUri *one = v1;
343 const SoupUri *two = v2;
345 if (one->protocol != two->protocol)
347 if (one->port != two->port)
350 return strcmp (one->host, two->host) == 0;
353 static SoupSessionHost *
354 soup_session_host_new (SoupSession *session, const SoupUri *source_uri)
356 SoupSessionHost *host;
358 host = g_new0 (SoupSessionHost, 1);
359 host->root_uri = soup_uri_copy_root (source_uri);
361 if (host->root_uri->protocol == SOUP_PROTOCOL_HTTPS &&
362 !session->priv->ssl_creds) {
363 session->priv->ssl_creds =
364 soup_ssl_get_client_credentials (session->priv->ssl_ca_file);
370 static SoupSessionHost *
371 get_host_for_message (SoupSession *session, SoupMessage *msg)
373 SoupSessionHost *host;
374 const SoupUri *source = soup_message_get_uri (msg);
376 host = g_hash_table_lookup (session->priv->hosts, source);
380 host = soup_session_host_new (session, source);
382 g_hash_table_insert (session->priv->hosts, host->root_uri, host);
387 static SoupSessionHost *
388 get_proxy_host (SoupSession *session)
390 if (session->priv->proxy_host)
391 return session->priv->proxy_host;
393 session->priv->proxy_host =
394 soup_session_host_new (session, session->priv->proxy_uri);
396 return session->priv->proxy_host;
400 free_realm (gpointer path, gpointer scheme_realm, gpointer data)
403 g_free (scheme_realm);
407 free_auth (gpointer scheme_realm, gpointer auth, gpointer data)
409 g_free (scheme_realm);
410 g_object_unref (auth);
414 free_host (SoupSessionHost *host, SoupSession *session)
416 while (host->connections) {
417 SoupConnection *conn = host->connections->data;
419 host->connections = g_slist_remove (host->connections, conn);
420 soup_connection_disconnect (conn);
423 if (host->auth_realms) {
424 g_hash_table_foreach (host->auth_realms, free_realm, NULL);
425 g_hash_table_destroy (host->auth_realms);
428 g_hash_table_foreach (host->auths, free_auth, NULL);
429 g_hash_table_destroy (host->auths);
432 soup_uri_free (host->root_uri);
438 lookup_auth (SoupSession *session, SoupMessage *msg, gboolean proxy)
440 SoupSessionHost *host;
442 const char *realm, *const_path;
445 host = get_proxy_host (session);
448 host = get_host_for_message (session, msg);
449 const_path = soup_message_get_uri (msg)->path;
451 g_return_val_if_fail (host != NULL, NULL);
453 if (!host->auth_realms)
456 path = g_strdup (const_path);
459 realm = g_hash_table_lookup (host->auth_realms, path);
463 dir = strrchr (path, '/');
470 return g_hash_table_lookup (host->auths, realm);
476 invalidate_auth (SoupSessionHost *host, SoupAuth *auth)
481 realm = g_strdup_printf ("%s:%s",
482 soup_auth_get_scheme_name (auth),
483 soup_auth_get_realm (auth));
485 if (g_hash_table_lookup_extended (host->auths, realm, &key, &value) &&
486 auth == (SoupAuth *)value) {
487 g_hash_table_remove (host->auths, realm);
489 g_object_unref (auth);
495 authenticate_auth (SoupSession *session, SoupAuth *auth,
496 SoupMessage *msg, gboolean prior_auth_failed,
500 char *username = NULL, *password = NULL;
503 uri = session->priv->proxy_uri;
505 uri = soup_message_get_uri (msg);
507 if (uri->passwd && !prior_auth_failed) {
508 soup_auth_authenticate (auth, uri->user, uri->passwd);
512 g_signal_emit (session, signals[prior_auth_failed ? REAUTHENTICATE : AUTHENTICATE], 0,
513 msg, soup_auth_get_scheme_name (auth),
514 soup_auth_get_realm (auth),
515 &username, &password);
516 if (username || password)
517 soup_auth_authenticate (auth, username, password);
521 memset (password, 0, strlen (password));
525 return soup_auth_is_authenticated (auth);
529 update_auth_internal (SoupSession *session, SoupMessage *msg,
530 const GSList *headers, gboolean proxy,
531 gboolean got_unauthorized)
533 SoupSessionHost *host;
534 SoupAuth *new_auth, *prior_auth, *old_auth;
535 gpointer old_path, old_realm;
536 const SoupUri *msg_uri;
540 gboolean prior_auth_failed = FALSE;
543 host = get_proxy_host (session);
545 host = get_host_for_message (session, msg);
547 g_return_val_if_fail (host != NULL, FALSE);
549 /* Try to construct a new auth from the headers; if we can't,
550 * there's no way we'll be able to authenticate.
552 msg_uri = soup_message_get_uri (msg);
553 new_auth = soup_auth_new_from_header_list (headers);
557 /* See if this auth is the same auth we used last time */
558 prior_auth = lookup_auth (session, msg, proxy);
560 G_OBJECT_TYPE (prior_auth) == G_OBJECT_TYPE (new_auth) &&
561 !strcmp (soup_auth_get_realm (prior_auth),
562 soup_auth_get_realm (new_auth))) {
563 if (!got_unauthorized) {
564 /* The user is just trying to preauthenticate
565 * using information we already have, so
566 * there's nothing more that needs to be done.
568 g_object_unref (new_auth);
572 /* The server didn't like the username/password we
573 * provided before. Invalidate it and note this fact.
575 invalidate_auth (host, prior_auth);
576 prior_auth_failed = TRUE;
579 if (!host->auth_realms) {
580 host->auth_realms = g_hash_table_new (g_str_hash, g_str_equal);
581 host->auths = g_hash_table_new (g_str_hash, g_str_equal);
584 /* Record where this auth realm is used */
585 realm = g_strdup_printf ("%s:%s",
586 soup_auth_get_scheme_name (new_auth),
587 soup_auth_get_realm (new_auth));
590 * RFC 2617 is somewhat unclear about the scope of protection
591 * spaces with regard to proxies. The only mention of it is
592 * as an aside in section 3.2.1, where it is defining the fields
593 * of a Digest challenge and says that the protection space is
594 * always the entire proxy. Is this the case for all authentication
595 * schemes or just Digest? Who knows, but we're assuming all.
598 pspace = g_slist_prepend (NULL, g_strdup (""));
600 pspace = soup_auth_get_protection_space (new_auth, msg_uri);
602 for (p = pspace; p; p = p->next) {
604 if (g_hash_table_lookup_extended (host->auth_realms, path,
605 &old_path, &old_realm)) {
606 g_hash_table_remove (host->auth_realms, old_path);
611 g_hash_table_insert (host->auth_realms,
612 g_strdup (path), g_strdup (realm));
614 soup_auth_free_protection_space (new_auth, pspace);
616 /* Now, make sure the auth is recorded. (If there's a
617 * pre-existing auth, we keep that rather than the new one,
618 * since the old one might already be authenticated.)
620 old_auth = g_hash_table_lookup (host->auths, realm);
623 g_object_unref (new_auth);
626 g_hash_table_insert (host->auths, realm, new_auth);
628 /* If we need to authenticate, try to do it. */
629 if (!soup_auth_is_authenticated (new_auth)) {
630 return authenticate_auth (session, new_auth, msg,
631 prior_auth_failed, proxy);
634 /* Otherwise we're good. */
639 connection_authenticate (SoupConnection *conn, SoupMessage *msg,
640 const char *auth_type, const char *auth_realm,
641 char **username, char **password, gpointer session)
643 g_signal_emit (session, signals[AUTHENTICATE], 0,
644 msg, auth_type, auth_realm, username, password);
648 connection_reauthenticate (SoupConnection *conn, SoupMessage *msg,
649 const char *auth_type, const char *auth_realm,
650 char **username, char **password,
653 g_signal_emit (conn, signals[REAUTHENTICATE], 0,
654 msg, auth_type, auth_realm, username, password);
659 authorize_handler (SoupMessage *msg, gpointer user_data)
661 SoupSession *session = user_data;
662 const GSList *headers;
665 if (msg->status_code == SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED) {
666 headers = soup_message_get_header_list (msg->response_headers,
667 "Proxy-Authenticate");
670 headers = soup_message_get_header_list (msg->response_headers,
677 if (update_auth_internal (session, msg, headers, proxy, TRUE))
678 soup_session_requeue_message (session, msg);
682 redirect_handler (SoupMessage *msg, gpointer user_data)
684 SoupSession *session = user_data;
688 new_loc = soup_message_get_header (msg->response_headers, "Location");
691 new_uri = soup_uri_new (new_loc);
693 goto INVALID_REDIRECT;
695 soup_message_set_uri (msg, new_uri);
696 soup_uri_free (new_uri);
698 soup_session_requeue_message (session, msg);
702 soup_message_set_status_full (msg,
703 SOUP_STATUS_MALFORMED,
704 "Invalid Redirect URL");
708 request_restarted (SoupMessage *req, gpointer session)
710 run_queue (session, FALSE);
714 request_finished (SoupMessage *req, gpointer user_data)
716 req->status = SOUP_MESSAGE_STATUS_FINISHED;
720 final_finished (SoupMessage *req, gpointer user_data)
722 SoupSession *session = user_data;
724 if (!SOUP_MESSAGE_IS_STARTING (req)) {
725 soup_message_queue_remove_message (session->priv->queue, req);
727 g_signal_handlers_disconnect_by_func (req, request_finished, session);
728 g_signal_handlers_disconnect_by_func (req, final_finished, session);
729 g_object_unref (req);
732 run_queue (session, FALSE);
736 add_auth (SoupSession *session, SoupMessage *msg, gboolean proxy)
738 const char *header = proxy ? "Proxy-Authorization" : "Authorization";
742 soup_message_remove_header (msg->request_headers, header);
744 auth = lookup_auth (session, msg, proxy);
747 if (!soup_auth_is_authenticated (auth) &&
748 !authenticate_auth (session, auth, msg, FALSE, proxy))
751 token = soup_auth_get_authorization (auth, msg);
753 soup_message_add_header (msg->request_headers, header, token);
759 send_request (SoupSession *session, SoupMessage *req, SoupConnection *conn)
761 req->status = SOUP_MESSAGE_STATUS_RUNNING;
763 add_auth (session, req, FALSE);
764 if (session->priv->proxy_uri)
765 add_auth (session, req, TRUE);
766 soup_connection_send_request (conn, req);
770 find_oldest_connection (gpointer key, gpointer host, gpointer data)
772 SoupConnection *conn = key, **oldest = data;
774 /* Don't prune a connection that hasn't even been used yet. */
775 if (soup_connection_last_used (conn) == 0)
778 if (!*oldest || (soup_connection_last_used (conn) <
779 soup_connection_last_used (*oldest)))
784 try_prune_connection (SoupSession *session)
786 SoupConnection *oldest = NULL;
788 g_hash_table_foreach (session->priv->conns, find_oldest_connection,
791 soup_connection_disconnect (oldest);
792 g_object_unref (oldest);
798 static void connection_closed (SoupConnection *conn, SoupSession *session);
801 cleanup_connection (SoupSession *session, SoupConnection *conn)
803 SoupSessionHost *host =
804 g_hash_table_lookup (session->priv->conns, conn);
806 g_return_if_fail (host != NULL);
808 g_hash_table_remove (session->priv->conns, conn);
809 g_signal_handlers_disconnect_by_func (conn, connection_closed, session);
810 session->priv->num_conns--;
812 host->connections = g_slist_remove (host->connections, conn);
817 connection_closed (SoupConnection *conn, SoupSession *session)
819 cleanup_connection (session, conn);
821 /* Run the queue in case anyone was waiting for a connection
824 run_queue (session, FALSE);
828 got_connection (SoupConnection *conn, guint status, gpointer user_data)
830 SoupSession *session = user_data;
831 SoupSessionHost *host = g_hash_table_lookup (session->priv->conns, conn);
833 g_return_if_fail (host != NULL);
835 if (status == SOUP_STATUS_OK) {
836 host->connections = g_slist_prepend (host->connections, conn);
837 run_queue (session, FALSE);
842 cleanup_connection (session, conn);
843 g_object_unref (conn);
845 if (host->connections) {
846 /* Something went wrong this time, but we have at
847 * least one open connection to this host. So just
848 * leave the message in the queue so it can use that
849 * connection once it's free.
854 /* Flush any queued messages for this host */
855 host->error = status;
856 run_queue (session, FALSE);
858 if (status != SOUP_STATUS_CANT_RESOLVE &&
859 status != SOUP_STATUS_CANT_RESOLVE_PROXY) {
860 /* If the error was "can't resolve", then it's not likely
861 * to improve. But if it was something else, it may have
862 * been transient, so we clear the error so the user can
870 run_queue (SoupSession *session, gboolean try_pruning)
872 SoupMessageQueueIter iter;
874 SoupConnection *conn;
875 SoupSessionHost *host;
876 gboolean skipped_any = FALSE, started_any = FALSE;
879 /* FIXME: prefer CONNECTING messages */
882 for (msg = soup_message_queue_first (session->priv->queue, &iter); msg; msg = soup_message_queue_next (session->priv->queue, &iter)) {
884 if (!SOUP_MESSAGE_IS_STARTING (msg))
887 host = get_host_for_message (session, msg);
889 /* If the hostname is known to be bad, fail right away */
891 soup_message_set_status (msg, host->error);
892 msg->status = SOUP_MESSAGE_STATUS_FINISHED;
893 soup_message_finished (msg);
896 /* If there is an idle connection, use it */
897 for (conns = host->connections; conns; conns = conns->next) {
898 if (!soup_connection_is_in_use (conns->data))
902 send_request (session, msg, conns->data);
907 if (msg->status == SOUP_MESSAGE_STATUS_CONNECTING) {
908 /* We already started a connection for this
909 * message, so don't start another one.
914 /* If we have the max number of per-host connections
915 * or total connections open, we'll have to wait.
917 if (host->num_conns >= session->priv->max_conns_per_host)
919 else if (session->priv->num_conns >= session->priv->max_conns) {
920 /* In this case, closing an idle connection
921 * somewhere else would let us open one here.
927 /* Otherwise, open a new connection */
928 conn = g_object_new (
929 (session->priv->use_ntlm ?
930 SOUP_TYPE_CONNECTION_NTLM : SOUP_TYPE_CONNECTION),
931 SOUP_CONNECTION_ORIGIN_URI, host->root_uri,
932 SOUP_CONNECTION_PROXY_URI, session->priv->proxy_uri,
933 SOUP_CONNECTION_SSL_CREDENTIALS, session->priv->ssl_creds,
935 g_signal_connect (conn, "authenticate",
936 G_CALLBACK (connection_authenticate),
938 g_signal_connect (conn, "reauthenticate",
939 G_CALLBACK (connection_reauthenticate),
942 soup_connection_connect_async (conn, got_connection, session);
943 g_signal_connect (conn, "disconnected",
944 G_CALLBACK (connection_closed), session);
945 g_hash_table_insert (session->priv->conns, conn, host);
946 session->priv->num_conns++;
948 /* Increment the host's connection count, but don't add
949 * this connection to the list yet, since it's not ready.
953 /* Mark the request as connecting, so we don't try to
954 * open another new connection for it next time around.
956 msg->status = SOUP_MESSAGE_STATUS_CONNECTING;
961 if (try_pruning && skipped_any && !started_any) {
962 /* We didn't manage to start any message, but there is
963 * at least one message in the queue that could be
964 * sent if we pruned an idle connection from some
967 if (try_prune_connection (session)) {
977 queue_message (SoupSession *session, SoupMessage *req, gboolean requeue)
979 req->status = SOUP_MESSAGE_STATUS_QUEUED;
981 soup_message_queue_append (session->priv->queue, req);
982 run_queue (session, TRUE);
987 * soup_session_queue_message:
988 * @session: a #SoupSession
989 * @req: the message to queue
990 * @callback: a #SoupMessageCallbackFn which will be called after the
991 * message completes or when an unrecoverable error occurs.
992 * @user_data: a pointer passed to @callback.
994 * Queues the message @req for sending. All messages are processed
995 * while the glib main loop runs. If @req has been processed before,
996 * any resources related to the time it was last sent are freed.
998 * Upon message completion, the callback specified in @callback will
999 * be invoked. If after returning from this callback the message has
1000 * not been requeued, @req will be unreffed.
1003 soup_session_queue_message (SoupSession *session, SoupMessage *req,
1004 SoupMessageCallbackFn callback, gpointer user_data)
1006 g_return_if_fail (SOUP_IS_SESSION (session));
1007 g_return_if_fail (SOUP_IS_MESSAGE (req));
1009 g_signal_connect (req, "restarted",
1010 G_CALLBACK (request_restarted), session);
1012 g_signal_connect (req, "finished",
1013 G_CALLBACK (request_finished), session);
1016 g_signal_connect (req, "finished",
1017 G_CALLBACK (callback), user_data);
1020 g_signal_connect_after (req, "finished",
1021 G_CALLBACK (final_finished), session);
1023 soup_message_add_status_code_handler (req, SOUP_STATUS_UNAUTHORIZED,
1024 SOUP_HANDLER_POST_BODY,
1025 authorize_handler, session);
1026 soup_message_add_status_code_handler (req,
1027 SOUP_STATUS_PROXY_UNAUTHORIZED,
1028 SOUP_HANDLER_POST_BODY,
1029 authorize_handler, session);
1031 if (!(soup_message_get_flags (req) & SOUP_MESSAGE_NO_REDIRECT)) {
1032 soup_message_add_status_class_handler (
1033 req, SOUP_STATUS_CLASS_REDIRECT,
1034 SOUP_HANDLER_POST_BODY,
1035 redirect_handler, session);
1038 queue_message (session, req, FALSE);
1042 * soup_session_requeue_message:
1043 * @session: a #SoupSession
1044 * @req: the message to requeue
1046 * This causes @req to be placed back on the queue to be attempted
1050 soup_session_requeue_message (SoupSession *session, SoupMessage *req)
1052 g_return_if_fail (SOUP_IS_SESSION (session));
1053 g_return_if_fail (SOUP_IS_MESSAGE (req));
1055 queue_message (session, req, TRUE);
1060 * soup_session_send_message:
1061 * @session: a #SoupSession
1062 * @req: the message to send
1064 * Synchronously send @req. This call will not return until the
1065 * transfer is finished successfully or there is an unrecoverable
1068 * @req is not freed upon return.
1070 * Return value: the HTTP status code of the response
1073 soup_session_send_message (SoupSession *session, SoupMessage *req)
1075 g_return_val_if_fail (SOUP_IS_SESSION (session), SOUP_STATUS_MALFORMED);
1076 g_return_val_if_fail (SOUP_IS_MESSAGE (req), SOUP_STATUS_MALFORMED);
1078 /* Balance out the unref that final_finished will do */
1081 soup_session_queue_message (session, req, NULL, NULL);
1083 while (req->status != SOUP_MESSAGE_STATUS_FINISHED &&
1084 !SOUP_STATUS_IS_TRANSPORT_ERROR (req->status_code))
1085 g_main_iteration (TRUE);
1087 return req->status_code;
1091 * soup_session_abort:
1092 * @session: the session
1094 * Cancels all pending requests in @session.
1097 soup_session_abort (SoupSession *session)
1099 SoupMessageQueueIter iter;
1102 for (msg = soup_message_queue_first (session->priv->queue, &iter); msg; msg = soup_message_queue_next (session->priv->queue, &iter)) {
1103 soup_message_queue_remove (session->priv->queue, &iter);
1104 soup_message_cancel (msg);