|
rpm-build |
4f3c61 |
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
|
rpm-build |
4f3c61 |
/*
|
|
rpm-build |
4f3c61 |
* Copyright 2007-2012 Red Hat, Inc.
|
|
rpm-build |
4f3c61 |
*/
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
#include "test-utils.h"
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
#include <gio/gnetworking.h>
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
SoupServer *server;
|
|
rpm-build |
4f3c61 |
SoupURI *base_uri;
|
|
rpm-build |
4f3c61 |
GMutex server_mutex;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
forget_close (SoupMessage *msg, gpointer user_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
soup_message_headers_remove (msg->response_headers, "Connection");
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
close_socket (SoupMessage *msg, gpointer user_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupSocket *sock = user_data;
|
|
rpm-build |
4f3c61 |
int sockfd;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
/* Actually calling soup_socket_disconnect() here would cause
|
|
rpm-build |
4f3c61 |
* us to leak memory, so just shutdown the socket instead.
|
|
rpm-build |
4f3c61 |
*/
|
|
rpm-build |
4f3c61 |
sockfd = soup_socket_get_fd (sock);
|
|
rpm-build |
4f3c61 |
#ifdef G_OS_WIN32
|
|
rpm-build |
4f3c61 |
shutdown (sockfd, SD_SEND);
|
|
rpm-build |
4f3c61 |
#else
|
|
rpm-build |
4f3c61 |
shutdown (sockfd, SHUT_WR);
|
|
rpm-build |
4f3c61 |
#endif
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
/* Then add the missing data to the message now, so SoupServer
|
|
rpm-build |
4f3c61 |
* can clean up after itself properly.
|
|
rpm-build |
4f3c61 |
*/
|
|
rpm-build |
4f3c61 |
soup_message_body_append (msg->response_body, SOUP_MEMORY_STATIC,
|
|
rpm-build |
4f3c61 |
"foo", 3);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
timeout_socket (SoupSocket *sock, gpointer user_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
soup_socket_disconnect (sock);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
timeout_request_started (SoupServer *server, SoupMessage *msg,
|
|
rpm-build |
4f3c61 |
SoupClientContext *client, gpointer user_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupSocket *sock;
|
|
rpm-build |
4f3c61 |
GMainContext *context = g_main_context_get_thread_default ();
|
|
rpm-build |
4f3c61 |
guint readable;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_signal_handlers_disconnect_by_func (server, timeout_request_started, NULL);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
|
rpm-build |
4f3c61 |
sock = soup_client_context_get_socket (client);
|
|
rpm-build |
4f3c61 |
G_GNUC_END_IGNORE_DEPRECATIONS;
|
|
rpm-build |
4f3c61 |
readable = g_signal_connect (sock, "readable",
|
|
rpm-build |
4f3c61 |
G_CALLBACK (timeout_socket), NULL);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_mutex_unlock (&server_mutex);
|
|
rpm-build |
4f3c61 |
while (soup_socket_is_connected (sock))
|
|
rpm-build |
4f3c61 |
g_main_context_iteration (context, TRUE);
|
|
rpm-build |
4f3c61 |
g_signal_handler_disconnect (sock, readable);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
setup_timeout_persistent (SoupServer *server, SoupSocket *sock)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
char buf[1];
|
|
rpm-build |
4f3c61 |
gsize nread;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
/* In order for the test to work correctly, we have to
|
|
rpm-build |
4f3c61 |
* close the connection *after* the client side writes
|
|
rpm-build |
4f3c61 |
* the request. To ensure that this happens reliably,
|
|
rpm-build |
4f3c61 |
* regardless of thread scheduling, we:
|
|
rpm-build |
4f3c61 |
*
|
|
rpm-build |
4f3c61 |
* 1. Try to read off the socket now, knowing it will
|
|
rpm-build |
4f3c61 |
* fail (since the client is waiting for us to
|
|
rpm-build |
4f3c61 |
* return a response). This will cause it to
|
|
rpm-build |
4f3c61 |
* emit "readable" later.
|
|
rpm-build |
4f3c61 |
* 2. Wait for the server to finish this request and
|
|
rpm-build |
4f3c61 |
* start reading the next one (and lock server_mutex
|
|
rpm-build |
4f3c61 |
* to interlock with the client and ensure that it
|
|
rpm-build |
4f3c61 |
* doesn't start writing its next request until
|
|
rpm-build |
4f3c61 |
* that point).
|
|
rpm-build |
4f3c61 |
* 3. Block until "readable" is emitted, meaning the
|
|
rpm-build |
4f3c61 |
* client has written its request.
|
|
rpm-build |
4f3c61 |
* 4. Close the socket.
|
|
rpm-build |
4f3c61 |
*/
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_socket_read (sock, buf, 1, &nread, NULL, NULL);
|
|
rpm-build |
4f3c61 |
g_mutex_lock (&server_mutex);
|
|
rpm-build |
4f3c61 |
g_signal_connect (server, "request-started",
|
|
rpm-build |
4f3c61 |
G_CALLBACK (timeout_request_started), NULL);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
server_callback (SoupServer *server, SoupMessage *msg,
|
|
rpm-build |
4f3c61 |
const char *path, GHashTable *query,
|
|
rpm-build |
4f3c61 |
SoupClientContext *context, gpointer data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
/* The way this gets used in the tests, we don't actually
|
|
rpm-build |
4f3c61 |
* need to hold it through the whole function, so it's simpler
|
|
rpm-build |
4f3c61 |
* to just release it right away.
|
|
rpm-build |
4f3c61 |
*/
|
|
rpm-build |
4f3c61 |
g_mutex_lock (&server_mutex);
|
|
rpm-build |
4f3c61 |
g_mutex_unlock (&server_mutex);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (msg->method != SOUP_METHOD_GET && msg->method != SOUP_METHOD_POST) {
|
|
rpm-build |
4f3c61 |
soup_message_set_status (msg, SOUP_STATUS_NOT_IMPLEMENTED);
|
|
rpm-build |
4f3c61 |
return;
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (g_str_has_prefix (path, "/content-length/")) {
|
|
rpm-build |
4f3c61 |
gboolean too_long = strcmp (path, "/content-length/long") == 0;
|
|
rpm-build |
4f3c61 |
gboolean no_close = strcmp (path, "/content-length/noclose") == 0;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_message_set_status (msg, SOUP_STATUS_OK);
|
|
rpm-build |
4f3c61 |
soup_message_set_response (msg, "text/plain",
|
|
rpm-build |
4f3c61 |
SOUP_MEMORY_STATIC, "foobar", 6);
|
|
rpm-build |
4f3c61 |
if (too_long)
|
|
rpm-build |
4f3c61 |
soup_message_headers_set_content_length (msg->response_headers, 9);
|
|
rpm-build |
4f3c61 |
soup_message_headers_append (msg->response_headers,
|
|
rpm-build |
4f3c61 |
"Connection", "close");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (too_long) {
|
|
rpm-build |
4f3c61 |
SoupSocket *sock;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
/* soup-message-io will wait for us to add
|
|
rpm-build |
4f3c61 |
* another chunk after the first, to fill out
|
|
rpm-build |
4f3c61 |
* the declared Content-Length. Instead, we
|
|
rpm-build |
4f3c61 |
* forcibly close the socket at that point.
|
|
rpm-build |
4f3c61 |
*/
|
|
rpm-build |
4f3c61 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
|
rpm-build |
4f3c61 |
sock = soup_client_context_get_socket (context);
|
|
rpm-build |
4f3c61 |
G_GNUC_END_IGNORE_DEPRECATIONS;
|
|
rpm-build |
4f3c61 |
g_signal_connect (msg, "wrote-chunk",
|
|
rpm-build |
4f3c61 |
G_CALLBACK (close_socket), sock);
|
|
rpm-build |
4f3c61 |
} else if (no_close) {
|
|
rpm-build |
4f3c61 |
/* Remove the 'Connection: close' after writing
|
|
rpm-build |
4f3c61 |
* the headers, so that when we check it after
|
|
rpm-build |
4f3c61 |
* writing the body, we'll think we aren't
|
|
rpm-build |
4f3c61 |
* supposed to close it.
|
|
rpm-build |
4f3c61 |
*/
|
|
rpm-build |
4f3c61 |
g_signal_connect (msg, "wrote-headers",
|
|
rpm-build |
4f3c61 |
G_CALLBACK (forget_close), NULL);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
return;
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (!strcmp (path, "/timeout-persistent")) {
|
|
rpm-build |
4f3c61 |
SoupSocket *sock;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
|
rpm-build |
4f3c61 |
sock = soup_client_context_get_socket (context);
|
|
rpm-build |
4f3c61 |
G_GNUC_END_IGNORE_DEPRECATIONS;
|
|
rpm-build |
4f3c61 |
setup_timeout_persistent (server, sock);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_message_set_status (msg, SOUP_STATUS_OK);
|
|
rpm-build |
4f3c61 |
soup_message_set_response (msg, "text/plain",
|
|
rpm-build |
4f3c61 |
SOUP_MEMORY_STATIC, "index", 5);
|
|
rpm-build |
4f3c61 |
return;
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_content_length_framing_test (void)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupSession *session;
|
|
rpm-build |
4f3c61 |
SoupMessage *msg;
|
|
rpm-build |
4f3c61 |
SoupURI *request_uri;
|
|
rpm-build |
4f3c61 |
goffset declared_length;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_test_bug ("611481");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " Content-Length larger than message body length\n");
|
|
rpm-build |
4f3c61 |
request_uri = soup_uri_new_with_base (base_uri, "/content-length/long");
|
|
rpm-build |
4f3c61 |
msg = soup_message_new_from_uri ("GET", request_uri);
|
|
rpm-build |
4f3c61 |
soup_session_send_message (session, msg);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_test_assert_message_status (msg, SOUP_STATUS_OK);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
declared_length = soup_message_headers_get_content_length (msg->response_headers);
|
|
rpm-build |
4f3c61 |
debug_printf (2, " Content-Length: %lu, body: %s\n",
|
|
rpm-build |
4f3c61 |
(gulong)declared_length, msg->response_body->data);
|
|
rpm-build |
4f3c61 |
g_assert_cmpint (msg->response_body->length, <, declared_length);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_uri_free (request_uri);
|
|
rpm-build |
4f3c61 |
g_object_unref (msg);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " Server claims 'Connection: close' but doesn't\n");
|
|
rpm-build |
4f3c61 |
request_uri = soup_uri_new_with_base (base_uri, "/content-length/noclose");
|
|
rpm-build |
4f3c61 |
msg = soup_message_new_from_uri ("GET", request_uri);
|
|
rpm-build |
4f3c61 |
soup_session_send_message (session, msg);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_test_assert_message_status (msg, SOUP_STATUS_OK);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
declared_length = soup_message_headers_get_content_length (msg->response_headers);
|
|
rpm-build |
4f3c61 |
g_assert_cmpint (msg->response_body->length, ==, declared_length);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_uri_free (request_uri);
|
|
rpm-build |
4f3c61 |
g_object_unref (msg);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_test_session_abort_unref (session);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
request_started_socket_collector (SoupSession *session, SoupMessage *msg,
|
|
rpm-build |
4f3c61 |
SoupSocket *socket, gpointer user_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupSocket **sockets = user_data;
|
|
rpm-build |
4f3c61 |
int i;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (2, " msg %p => socket %p\n", msg, socket);
|
|
rpm-build |
4f3c61 |
for (i = 0; i < 4; i++) {
|
|
rpm-build |
4f3c61 |
if (!sockets[i]) {
|
|
rpm-build |
4f3c61 |
/* We ref the socket to make sure that even if
|
|
rpm-build |
4f3c61 |
* it gets disconnected, it doesn't get freed,
|
|
rpm-build |
4f3c61 |
* since our checks would get messed up if the
|
|
rpm-build |
4f3c61 |
* slice allocator reused the same address for
|
|
rpm-build |
4f3c61 |
* two consecutive sockets.
|
|
rpm-build |
4f3c61 |
*/
|
|
rpm-build |
4f3c61 |
sockets[i] = g_object_ref (socket);
|
|
rpm-build |
4f3c61 |
break;
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_test_assert (i < 4, "socket queue overflowed");
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_timeout_test_for_session (SoupSession *session)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupMessage *msg;
|
|
rpm-build |
4f3c61 |
SoupSocket *sockets[4] = { NULL, NULL, NULL, NULL };
|
|
rpm-build |
4f3c61 |
SoupURI *timeout_uri;
|
|
rpm-build |
4f3c61 |
int i;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_signal_connect (session, "request-started",
|
|
rpm-build |
4f3c61 |
G_CALLBACK (request_started_socket_collector),
|
|
rpm-build |
4f3c61 |
&sockets);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " First message\n");
|
|
rpm-build |
4f3c61 |
timeout_uri = soup_uri_new_with_base (base_uri, "/timeout-persistent");
|
|
rpm-build |
4f3c61 |
msg = soup_message_new_from_uri ("GET", timeout_uri);
|
|
rpm-build |
4f3c61 |
soup_uri_free (timeout_uri);
|
|
rpm-build |
4f3c61 |
soup_session_send_message (session, msg);
|
|
rpm-build |
4f3c61 |
soup_test_assert_message_status (msg, SOUP_STATUS_OK);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (sockets[1]) {
|
|
rpm-build |
4f3c61 |
soup_test_assert (sockets[1] == NULL, "Message was retried");
|
|
rpm-build |
4f3c61 |
sockets[1] = sockets[2] = sockets[3] = NULL;
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
g_object_unref (msg);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
/* The server will grab server_mutex before returning the response,
|
|
rpm-build |
4f3c61 |
* and release it when it's ready for us to send the second request.
|
|
rpm-build |
4f3c61 |
*/
|
|
rpm-build |
4f3c61 |
g_mutex_lock (&server_mutex);
|
|
rpm-build |
4f3c61 |
g_mutex_unlock (&server_mutex);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " Second message\n");
|
|
rpm-build |
4f3c61 |
msg = soup_message_new_from_uri ("GET", base_uri);
|
|
rpm-build |
4f3c61 |
soup_session_send_message (session, msg);
|
|
rpm-build |
4f3c61 |
soup_test_assert_message_status (msg, SOUP_STATUS_OK);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_test_assert (sockets[1] == sockets[0],
|
|
rpm-build |
4f3c61 |
"Message was not retried on existing connection");
|
|
rpm-build |
4f3c61 |
soup_test_assert (sockets[2] != NULL,
|
|
rpm-build |
4f3c61 |
"Message was not retried after disconnect");
|
|
rpm-build |
4f3c61 |
soup_test_assert (sockets[2] != sockets[1],
|
|
rpm-build |
4f3c61 |
"Message was retried on closed connection");
|
|
rpm-build |
4f3c61 |
soup_test_assert (sockets[3] == NULL,
|
|
rpm-build |
4f3c61 |
"Message was retried again");
|
|
rpm-build |
4f3c61 |
g_object_unref (msg);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
for (i = 0; sockets[i]; i++)
|
|
rpm-build |
4f3c61 |
g_object_unref (sockets[i]);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_timeout_req_test_for_session (SoupSession *session)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupRequest *req;
|
|
rpm-build |
4f3c61 |
SoupMessage *msg;
|
|
rpm-build |
4f3c61 |
GInputStream *stream;
|
|
rpm-build |
4f3c61 |
SoupSocket *sockets[4] = { NULL, NULL, NULL, NULL };
|
|
rpm-build |
4f3c61 |
SoupURI *timeout_uri;
|
|
rpm-build |
4f3c61 |
GError *error = NULL;
|
|
rpm-build |
4f3c61 |
int i;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_signal_connect (session, "request-started",
|
|
rpm-build |
4f3c61 |
G_CALLBACK (request_started_socket_collector),
|
|
rpm-build |
4f3c61 |
&sockets);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " First request\n");
|
|
rpm-build |
4f3c61 |
timeout_uri = soup_uri_new_with_base (base_uri, "/timeout-persistent");
|
|
rpm-build |
4f3c61 |
req = soup_session_request_uri (session, timeout_uri, NULL);
|
|
rpm-build |
4f3c61 |
soup_uri_free (timeout_uri);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
stream = soup_test_request_send (req, NULL, 0, &error);
|
|
rpm-build |
4f3c61 |
if (error) {
|
|
rpm-build |
4f3c61 |
g_assert_no_error (error);
|
|
rpm-build |
4f3c61 |
g_clear_error (&error);
|
|
rpm-build |
4f3c61 |
} else {
|
|
rpm-build |
4f3c61 |
soup_test_request_read_all (req, stream, NULL, &error);
|
|
rpm-build |
4f3c61 |
if (error) {
|
|
rpm-build |
4f3c61 |
g_assert_no_error (error);
|
|
rpm-build |
4f3c61 |
g_clear_error (&error);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_test_request_close_stream (req, stream, NULL, &error);
|
|
rpm-build |
4f3c61 |
if (error) {
|
|
rpm-build |
4f3c61 |
g_assert_no_error (error);
|
|
rpm-build |
4f3c61 |
g_clear_error (&error);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
g_object_unref (stream);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (sockets[1]) {
|
|
rpm-build |
4f3c61 |
soup_test_assert (sockets[1] == NULL, "Message was retried");
|
|
rpm-build |
4f3c61 |
sockets[1] = sockets[2] = sockets[3] = NULL;
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
g_object_unref (req);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
/* The server will grab server_mutex before returning the response,
|
|
rpm-build |
4f3c61 |
* and release it when it's ready for us to send the second request.
|
|
rpm-build |
4f3c61 |
*/
|
|
rpm-build |
4f3c61 |
g_mutex_lock (&server_mutex);
|
|
rpm-build |
4f3c61 |
g_mutex_unlock (&server_mutex);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " Second request\n");
|
|
rpm-build |
4f3c61 |
req = soup_session_request_uri (session, base_uri, NULL);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
stream = soup_test_request_send (req, NULL, 0, &error);
|
|
rpm-build |
4f3c61 |
if (error) {
|
|
rpm-build |
4f3c61 |
g_assert_no_error (error);
|
|
rpm-build |
4f3c61 |
g_clear_error (&error);
|
|
rpm-build |
4f3c61 |
} else {
|
|
rpm-build |
4f3c61 |
soup_test_request_close_stream (req, stream, NULL, &error);
|
|
rpm-build |
4f3c61 |
if (error) {
|
|
rpm-build |
4f3c61 |
g_assert_no_error (error);
|
|
rpm-build |
4f3c61 |
g_clear_error (&error);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
g_object_unref (stream);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (req));
|
|
rpm-build |
4f3c61 |
soup_test_assert_message_status (msg, SOUP_STATUS_OK);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_test_assert (sockets[1] == sockets[0],
|
|
rpm-build |
4f3c61 |
"Message was not retried on existing connection");
|
|
rpm-build |
4f3c61 |
soup_test_assert (sockets[2] != NULL,
|
|
rpm-build |
4f3c61 |
"Message was not retried after disconnect");
|
|
rpm-build |
4f3c61 |
soup_test_assert (sockets[2] != sockets[1],
|
|
rpm-build |
4f3c61 |
"Message was retried on closed connection");
|
|
rpm-build |
4f3c61 |
soup_test_assert (sockets[3] == NULL,
|
|
rpm-build |
4f3c61 |
"Message was retried again");
|
|
rpm-build |
4f3c61 |
g_object_unref (msg);
|
|
rpm-build |
4f3c61 |
g_object_unref (req);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
for (i = 0; sockets[i]; i++)
|
|
rpm-build |
4f3c61 |
g_object_unref (sockets[i]);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_persistent_connection_timeout_test (void)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupSession *session;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_test_bug ("631525");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " Async session, message API\n");
|
|
rpm-build |
4f3c61 |
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
|
|
rpm-build |
4f3c61 |
do_timeout_test_for_session (session);
|
|
rpm-build |
4f3c61 |
soup_test_session_abort_unref (session);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " Async session, request API\n");
|
|
rpm-build |
4f3c61 |
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
|
|
rpm-build |
4f3c61 |
SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
|
|
rpm-build |
4f3c61 |
NULL);
|
|
rpm-build |
4f3c61 |
do_timeout_req_test_for_session (session);
|
|
rpm-build |
4f3c61 |
soup_test_session_abort_unref (session);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " Sync session, message API\n");
|
|
rpm-build |
4f3c61 |
session = soup_test_session_new (SOUP_TYPE_SESSION_SYNC, NULL);
|
|
rpm-build |
4f3c61 |
do_timeout_test_for_session (session);
|
|
rpm-build |
4f3c61 |
soup_test_session_abort_unref (session);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " Sync session, request API\n");
|
|
rpm-build |
4f3c61 |
session = soup_test_session_new (SOUP_TYPE_SESSION_SYNC, NULL);
|
|
rpm-build |
4f3c61 |
do_timeout_req_test_for_session (session);
|
|
rpm-build |
4f3c61 |
soup_test_session_abort_unref (session);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static GMainLoop *max_conns_loop;
|
|
rpm-build |
4f3c61 |
static int msgs_done;
|
|
rpm-build |
4f3c61 |
static guint quit_loop_timeout;
|
|
rpm-build |
4f3c61 |
#define MAX_CONNS 2
|
|
rpm-build |
4f3c61 |
#define TEST_CONNS (MAX_CONNS * 2) + 1
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static gboolean
|
|
rpm-build |
4f3c61 |
idle_start_server (gpointer data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
g_mutex_unlock (&server_mutex);
|
|
rpm-build |
4f3c61 |
return FALSE;
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static gboolean
|
|
rpm-build |
4f3c61 |
quit_loop (gpointer data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
quit_loop_timeout = 0;
|
|
rpm-build |
4f3c61 |
g_main_loop_quit (max_conns_loop);
|
|
rpm-build |
4f3c61 |
return FALSE;
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
max_conns_request_started (SoupSession *session, SoupMessage *msg,
|
|
rpm-build |
4f3c61 |
SoupSocket *socket, gpointer user_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
if (++msgs_done >= MAX_CONNS) {
|
|
rpm-build |
4f3c61 |
if (quit_loop_timeout)
|
|
rpm-build |
4f3c61 |
g_source_remove (quit_loop_timeout);
|
|
rpm-build |
4f3c61 |
quit_loop_timeout = g_timeout_add (100, quit_loop, NULL);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
max_conns_message_complete (SoupSession *session, SoupMessage *msg, gpointer user_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
if (++msgs_done == TEST_CONNS)
|
|
rpm-build |
4f3c61 |
g_main_loop_quit (max_conns_loop);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_max_conns_test_for_session (SoupSession *session)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupMessage *msgs[TEST_CONNS + 1];
|
|
rpm-build |
4f3c61 |
SoupMessageFlags flags;
|
|
rpm-build |
4f3c61 |
int i;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
max_conns_loop = g_main_loop_new (NULL, TRUE);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_mutex_lock (&server_mutex);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_signal_connect (session, "request-started",
|
|
rpm-build |
4f3c61 |
G_CALLBACK (max_conns_request_started), NULL);
|
|
rpm-build |
4f3c61 |
msgs_done = 0;
|
|
rpm-build |
4f3c61 |
for (i = 0; i < TEST_CONNS - 1; i++) {
|
|
rpm-build |
4f3c61 |
msgs[i] = soup_message_new_from_uri ("GET", base_uri);
|
|
rpm-build |
4f3c61 |
g_object_ref (msgs[i]);
|
|
rpm-build |
4f3c61 |
soup_session_queue_message (session, msgs[i],
|
|
rpm-build |
4f3c61 |
max_conns_message_complete, NULL);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_main_loop_run (max_conns_loop);
|
|
rpm-build |
4f3c61 |
g_assert_cmpint (msgs_done, ==, MAX_CONNS);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (quit_loop_timeout)
|
|
rpm-build |
4f3c61 |
g_source_remove (quit_loop_timeout);
|
|
rpm-build |
4f3c61 |
quit_loop_timeout = g_timeout_add (1000, quit_loop, NULL);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
/* Message with SOUP_MESSAGE_IGNORE_CONNECTION_LIMITS should start */
|
|
rpm-build |
4f3c61 |
msgs[i] = soup_message_new_from_uri ("GET", base_uri);
|
|
rpm-build |
4f3c61 |
flags = soup_message_get_flags (msgs[i]);
|
|
rpm-build |
4f3c61 |
soup_message_set_flags (msgs[i], flags | SOUP_MESSAGE_IGNORE_CONNECTION_LIMITS);
|
|
rpm-build |
4f3c61 |
g_object_ref (msgs[i]);
|
|
rpm-build |
4f3c61 |
soup_session_queue_message (session, msgs[i],
|
|
rpm-build |
4f3c61 |
max_conns_message_complete, NULL);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_main_loop_run (max_conns_loop);
|
|
rpm-build |
4f3c61 |
g_assert_cmpint (msgs_done, ==, MAX_CONNS + 1);
|
|
rpm-build |
4f3c61 |
g_signal_handlers_disconnect_by_func (session, max_conns_request_started, NULL);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
msgs_done = 0;
|
|
rpm-build |
4f3c61 |
g_idle_add (idle_start_server, NULL);
|
|
rpm-build |
4f3c61 |
if (quit_loop_timeout)
|
|
rpm-build |
4f3c61 |
g_source_remove (quit_loop_timeout);
|
|
rpm-build |
4f3c61 |
quit_loop_timeout = g_timeout_add (1000, quit_loop, NULL);
|
|
rpm-build |
4f3c61 |
g_main_loop_run (max_conns_loop);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
for (i = 0; i < TEST_CONNS; i++)
|
|
rpm-build |
4f3c61 |
soup_test_assert_message_status (msgs[i], SOUP_STATUS_OK);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (msgs_done != TEST_CONNS) {
|
|
rpm-build |
4f3c61 |
/* Clean up so we don't get a spurious "Leaked
|
|
rpm-build |
4f3c61 |
* session" error.
|
|
rpm-build |
4f3c61 |
*/
|
|
rpm-build |
4f3c61 |
for (i = 0; i < TEST_CONNS; i++)
|
|
rpm-build |
4f3c61 |
soup_session_cancel_message (session, msgs[i], SOUP_STATUS_CANCELLED);
|
|
rpm-build |
4f3c61 |
g_main_loop_run (max_conns_loop);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_main_loop_unref (max_conns_loop);
|
|
rpm-build |
4f3c61 |
if (quit_loop_timeout) {
|
|
rpm-build |
4f3c61 |
g_source_remove (quit_loop_timeout);
|
|
rpm-build |
4f3c61 |
quit_loop_timeout = 0;
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
for (i = 0; i < TEST_CONNS; i++)
|
|
rpm-build |
4f3c61 |
g_object_unref (msgs[i]);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_max_conns_test (void)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupSession *session;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_test_bug ("634422");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " Async session\n");
|
|
rpm-build |
4f3c61 |
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
|
|
rpm-build |
4f3c61 |
SOUP_SESSION_MAX_CONNS, MAX_CONNS,
|
|
rpm-build |
4f3c61 |
NULL);
|
|
rpm-build |
4f3c61 |
do_max_conns_test_for_session (session);
|
|
rpm-build |
4f3c61 |
soup_test_session_abort_unref (session);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " Sync session\n");
|
|
rpm-build |
4f3c61 |
session = soup_test_session_new (SOUP_TYPE_SESSION_SYNC,
|
|
rpm-build |
4f3c61 |
SOUP_SESSION_MAX_CONNS, MAX_CONNS,
|
|
rpm-build |
4f3c61 |
NULL);
|
|
rpm-build |
4f3c61 |
do_max_conns_test_for_session (session);
|
|
rpm-build |
4f3c61 |
soup_test_session_abort_unref (session);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
np_request_started (SoupSession *session, SoupMessage *msg,
|
|
rpm-build |
4f3c61 |
SoupSocket *socket, gpointer user_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupSocket **save_socket = user_data;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
*save_socket = g_object_ref (socket);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
np_request_unqueued (SoupSession *session, SoupMessage *msg,
|
|
rpm-build |
4f3c61 |
gpointer user_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupSocket *socket = *(SoupSocket **)user_data;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_assert_false (soup_socket_is_connected (socket));
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
np_request_finished (SoupSession *session, SoupMessage *msg,
|
|
rpm-build |
4f3c61 |
gpointer user_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
GMainLoop *loop = user_data;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_main_loop_quit (loop);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_non_persistent_test_for_session (SoupSession *session)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupMessage *msg;
|
|
rpm-build |
4f3c61 |
SoupSocket *socket = NULL;
|
|
rpm-build |
4f3c61 |
GMainLoop *loop;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
loop = g_main_loop_new (NULL, FALSE);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_signal_connect (session, "request-started",
|
|
rpm-build |
4f3c61 |
G_CALLBACK (np_request_started),
|
|
rpm-build |
4f3c61 |
&socket);
|
|
rpm-build |
4f3c61 |
g_signal_connect (session, "request-unqueued",
|
|
rpm-build |
4f3c61 |
G_CALLBACK (np_request_unqueued),
|
|
rpm-build |
4f3c61 |
&socket);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
msg = soup_message_new_from_uri ("GET", base_uri);
|
|
rpm-build |
4f3c61 |
soup_message_headers_append (msg->request_headers, "Connection", "close");
|
|
rpm-build |
4f3c61 |
g_object_ref (msg);
|
|
rpm-build |
4f3c61 |
soup_session_queue_message (session, msg,
|
|
rpm-build |
4f3c61 |
np_request_finished, loop);
|
|
rpm-build |
4f3c61 |
g_main_loop_run (loop);
|
|
rpm-build |
4f3c61 |
g_main_loop_unref (loop);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_test_assert_message_status (msg, SOUP_STATUS_OK);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_object_unref (msg);
|
|
rpm-build |
4f3c61 |
g_object_unref (socket);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_non_persistent_connection_test (void)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupSession *session;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_test_bug ("578990");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " Async session\n");
|
|
rpm-build |
4f3c61 |
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
|
|
rpm-build |
4f3c61 |
do_non_persistent_test_for_session (session);
|
|
rpm-build |
4f3c61 |
soup_test_session_abort_unref (session);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " Sync session\n");
|
|
rpm-build |
4f3c61 |
session = soup_test_session_new (SOUP_TYPE_SESSION_SYNC, NULL);
|
|
rpm-build |
4f3c61 |
do_non_persistent_test_for_session (session);
|
|
rpm-build |
4f3c61 |
soup_test_session_abort_unref (session);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_non_idempotent_test_for_session (SoupSession *session)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupMessage *msg;
|
|
rpm-build |
4f3c61 |
SoupSocket *sockets[4] = { NULL, NULL, NULL, NULL };
|
|
rpm-build |
4f3c61 |
int i;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_signal_connect (session, "request-started",
|
|
rpm-build |
4f3c61 |
G_CALLBACK (request_started_socket_collector),
|
|
rpm-build |
4f3c61 |
&sockets);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (2, " GET\n");
|
|
rpm-build |
4f3c61 |
msg = soup_message_new_from_uri ("GET", base_uri);
|
|
rpm-build |
4f3c61 |
soup_session_send_message (session, msg);
|
|
rpm-build |
4f3c61 |
soup_test_assert_message_status (msg, SOUP_STATUS_OK);
|
|
rpm-build |
4f3c61 |
if (sockets[1]) {
|
|
rpm-build |
4f3c61 |
soup_test_assert (sockets[1] == NULL, "Message was retried");
|
|
rpm-build |
4f3c61 |
sockets[1] = sockets[2] = sockets[3] = NULL;
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
g_object_unref (msg);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (2, " POST\n");
|
|
rpm-build |
4f3c61 |
msg = soup_message_new_from_uri ("POST", base_uri);
|
|
rpm-build |
4f3c61 |
soup_session_send_message (session, msg);
|
|
rpm-build |
4f3c61 |
soup_test_assert_message_status (msg, SOUP_STATUS_OK);
|
|
rpm-build |
4f3c61 |
soup_test_assert (sockets[1] != sockets[0],
|
|
rpm-build |
4f3c61 |
"Message was sent on existing connection");
|
|
rpm-build |
4f3c61 |
soup_test_assert (sockets[2] == NULL,
|
|
rpm-build |
4f3c61 |
"Too many connections used");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_object_unref (msg);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
for (i = 0; sockets[i]; i++)
|
|
rpm-build |
4f3c61 |
g_object_unref (sockets[i]);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_non_idempotent_connection_test (void)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupSession *session;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " Async session\n");
|
|
rpm-build |
4f3c61 |
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
|
|
rpm-build |
4f3c61 |
do_non_idempotent_test_for_session (session);
|
|
rpm-build |
4f3c61 |
soup_test_session_abort_unref (session);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " Sync session\n");
|
|
rpm-build |
4f3c61 |
session = soup_test_session_new (SOUP_TYPE_SESSION_SYNC, NULL);
|
|
rpm-build |
4f3c61 |
do_non_idempotent_test_for_session (session);
|
|
rpm-build |
4f3c61 |
soup_test_session_abort_unref (session);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
#define HTTP_SERVER "http://127.0.0.1:47524"
|
|
rpm-build |
4f3c61 |
#define HTTPS_SERVER "https://127.0.0.1:47525"
|
|
rpm-build |
4f3c61 |
#define HTTP_PROXY "http://127.0.0.1:47526"
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static SoupConnectionState state_transitions[] = {
|
|
rpm-build |
4f3c61 |
/* NEW -> */ SOUP_CONNECTION_CONNECTING,
|
|
rpm-build |
4f3c61 |
/* CONNECTING -> */ SOUP_CONNECTION_IN_USE,
|
|
rpm-build |
4f3c61 |
/* IDLE -> */ SOUP_CONNECTION_DISCONNECTED,
|
|
rpm-build |
4f3c61 |
/* IN_USE -> */ SOUP_CONNECTION_IDLE,
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
/* REMOTE_DISCONNECTED */ -1,
|
|
rpm-build |
4f3c61 |
/* DISCONNECTED */ -1,
|
|
rpm-build |
4f3c61 |
};
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static const char *state_names[] = {
|
|
rpm-build |
4f3c61 |
"NEW", "CONNECTING", "IDLE", "IN_USE",
|
|
rpm-build |
4f3c61 |
"REMOTE_DISCONNECTED", "DISCONNECTED"
|
|
rpm-build |
4f3c61 |
};
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
connection_state_changed (GObject *object, GParamSpec *param,
|
|
rpm-build |
4f3c61 |
gpointer user_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupConnectionState *state = user_data;
|
|
rpm-build |
4f3c61 |
SoupConnectionState new_state;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_object_get (object, "state", &new_state, NULL);
|
|
rpm-build |
4f3c61 |
debug_printf (2, " %s -> %s\n",
|
|
rpm-build |
4f3c61 |
state_names[*state], state_names[new_state]);
|
|
rpm-build |
4f3c61 |
soup_test_assert (state_transitions[*state] == new_state,
|
|
rpm-build |
4f3c61 |
"Unexpected transition: %s -> %s\n",
|
|
rpm-build |
4f3c61 |
state_names[*state], state_names[new_state]);
|
|
rpm-build |
4f3c61 |
*state = new_state;
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
connection_created (SoupSession *session, GObject *conn,
|
|
rpm-build |
4f3c61 |
gpointer user_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupConnectionState *state = user_data;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_object_get (conn, "state", state, NULL);
|
|
rpm-build |
4f3c61 |
g_assert_cmpint (*state, ==, SOUP_CONNECTION_NEW);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_signal_connect (conn, "notify::state",
|
|
rpm-build |
4f3c61 |
G_CALLBACK (connection_state_changed),
|
|
rpm-build |
4f3c61 |
state);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_one_connection_state_test (SoupSession *session, const char *uri)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupMessage *msg;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
msg = soup_message_new ("GET", uri);
|
|
rpm-build |
4f3c61 |
soup_session_send_message (session, msg);
|
|
rpm-build |
4f3c61 |
soup_test_assert_message_status (msg, SOUP_STATUS_OK);
|
|
rpm-build |
4f3c61 |
g_object_unref (msg);
|
|
rpm-build |
4f3c61 |
soup_session_abort (session);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_connection_state_test_for_session (SoupSession *session)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupConnectionState state;
|
|
rpm-build |
4f3c61 |
SoupURI *proxy_uri;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_signal_connect (session, "connection-created",
|
|
rpm-build |
4f3c61 |
G_CALLBACK (connection_created),
|
|
rpm-build |
4f3c61 |
&state);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " http\n");
|
|
rpm-build |
4f3c61 |
do_one_connection_state_test (session, HTTP_SERVER);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (tls_available) {
|
|
rpm-build |
4f3c61 |
debug_printf (1, " https\n");
|
|
rpm-build |
4f3c61 |
do_one_connection_state_test (session, HTTPS_SERVER);
|
|
rpm-build |
4f3c61 |
} else
|
|
rpm-build |
4f3c61 |
debug_printf (1, " https -- SKIPPING\n");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
proxy_uri = soup_uri_new (HTTP_PROXY);
|
|
rpm-build |
4f3c61 |
g_object_set (G_OBJECT (session),
|
|
rpm-build |
4f3c61 |
SOUP_SESSION_PROXY_URI, proxy_uri,
|
|
rpm-build |
4f3c61 |
NULL);
|
|
rpm-build |
4f3c61 |
soup_uri_free (proxy_uri);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " http with proxy\n");
|
|
rpm-build |
4f3c61 |
do_one_connection_state_test (session, HTTP_SERVER);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (tls_available) {
|
|
rpm-build |
4f3c61 |
debug_printf (1, " https with proxy\n");
|
|
rpm-build |
4f3c61 |
do_one_connection_state_test (session, HTTPS_SERVER);
|
|
rpm-build |
4f3c61 |
} else
|
|
rpm-build |
4f3c61 |
debug_printf (1, " https with proxy -- SKIPPING\n");
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_connection_state_test (void)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupSession *session;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
SOUP_TEST_SKIP_IF_NO_APACHE;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " Async session\n");
|
|
rpm-build |
4f3c61 |
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
|
|
rpm-build |
4f3c61 |
do_connection_state_test_for_session (session);
|
|
rpm-build |
4f3c61 |
soup_test_session_abort_unref (session);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " Sync session\n");
|
|
rpm-build |
4f3c61 |
session = soup_test_session_new (SOUP_TYPE_SESSION_SYNC, NULL);
|
|
rpm-build |
4f3c61 |
do_connection_state_test_for_session (session);
|
|
rpm-build |
4f3c61 |
soup_test_session_abort_unref (session);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static const char *event_names[] = {
|
|
rpm-build |
4f3c61 |
"RESOLVING", "RESOLVED", "CONNECTING", "CONNECTED",
|
|
rpm-build |
4f3c61 |
"PROXY_NEGOTIATING", "PROXY_NEGOTIATED",
|
|
rpm-build |
4f3c61 |
"TLS_HANDSHAKING", "TLS_HANDSHAKED", "COMPLETE"
|
|
rpm-build |
4f3c61 |
};
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static const char event_abbrevs[] = {
|
|
rpm-build |
4f3c61 |
'r', 'R', 'c', 'C', 'p', 'P', 't', 'T', 'x', '\0'
|
|
rpm-build |
4f3c61 |
};
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static const char *
|
|
rpm-build |
4f3c61 |
event_name_from_abbrev (char abbrev)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
int evt;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
for (evt = 0; event_abbrevs[evt]; evt++) {
|
|
rpm-build |
4f3c61 |
if (event_abbrevs[evt] == abbrev)
|
|
rpm-build |
4f3c61 |
return event_names[evt];
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
return "???";
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
network_event (SoupMessage *msg, GSocketClientEvent event,
|
|
rpm-build |
4f3c61 |
GIOStream *connection, gpointer user_data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
const char **events = user_data;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (2, " %s\n", event_names[event]);
|
|
rpm-build |
4f3c61 |
soup_test_assert (**events == event_abbrevs[event],
|
|
rpm-build |
4f3c61 |
"Unexpected event: %s (expected %s)",
|
|
rpm-build |
4f3c61 |
event_names[event],
|
|
rpm-build |
4f3c61 |
event_name_from_abbrev (**events));
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (**events == event_abbrevs[event]) {
|
|
rpm-build |
4f3c61 |
if (event == G_SOCKET_CLIENT_RESOLVING ||
|
|
rpm-build |
4f3c61 |
event == G_SOCKET_CLIENT_RESOLVED) {
|
|
rpm-build |
4f3c61 |
soup_test_assert (connection == NULL,
|
|
rpm-build |
4f3c61 |
"Unexpectedly got connection (%s) with '%s' event",
|
|
rpm-build |
4f3c61 |
G_OBJECT_TYPE_NAME (connection),
|
|
rpm-build |
4f3c61 |
event_names[event]);
|
|
rpm-build |
4f3c61 |
} else if (event < G_SOCKET_CLIENT_TLS_HANDSHAKING) {
|
|
rpm-build |
4f3c61 |
soup_test_assert (G_IS_SOCKET_CONNECTION (connection),
|
|
rpm-build |
4f3c61 |
"Unexpectedly got %s with '%s' event",
|
|
rpm-build |
4f3c61 |
G_OBJECT_TYPE_NAME (connection),
|
|
rpm-build |
4f3c61 |
event_names[event]);
|
|
rpm-build |
4f3c61 |
} else if (event == G_SOCKET_CLIENT_TLS_HANDSHAKING ||
|
|
rpm-build |
4f3c61 |
event == G_SOCKET_CLIENT_TLS_HANDSHAKED) {
|
|
rpm-build |
4f3c61 |
soup_test_assert (G_IS_TLS_CLIENT_CONNECTION (connection),
|
|
rpm-build |
4f3c61 |
"Unexpectedly got %s with '%s' event",
|
|
rpm-build |
4f3c61 |
G_OBJECT_TYPE_NAME (connection),
|
|
rpm-build |
4f3c61 |
event_names[event]);
|
|
rpm-build |
4f3c61 |
} else if (event == G_SOCKET_CLIENT_COMPLETE) {
|
|
rpm-build |
4f3c61 |
/* See if the previous expected event was TLS_HANDSHAKED */
|
|
rpm-build |
4f3c61 |
if ((*events)[-1] == 'T') {
|
|
rpm-build |
4f3c61 |
soup_test_assert (G_IS_TLS_CLIENT_CONNECTION (connection),
|
|
rpm-build |
4f3c61 |
"Unexpectedly got %s with '%s' event",
|
|
rpm-build |
4f3c61 |
G_OBJECT_TYPE_NAME (connection),
|
|
rpm-build |
4f3c61 |
event_names[event]);
|
|
rpm-build |
4f3c61 |
} else {
|
|
rpm-build |
4f3c61 |
soup_test_assert (G_IS_SOCKET_CONNECTION (connection),
|
|
rpm-build |
4f3c61 |
"Unexpectedly got %s with '%s' event",
|
|
rpm-build |
4f3c61 |
G_OBJECT_TYPE_NAME (connection),
|
|
rpm-build |
4f3c61 |
event_names[event]);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
*events = *events + 1;
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_one_connection_event_test (SoupSession *session, const char *uri,
|
|
rpm-build |
4f3c61 |
const char *events)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupMessage *msg;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
msg = soup_message_new ("GET", uri);
|
|
rpm-build |
4f3c61 |
g_signal_connect (msg, "network-event",
|
|
rpm-build |
4f3c61 |
G_CALLBACK (network_event),
|
|
rpm-build |
4f3c61 |
&events);
|
|
rpm-build |
4f3c61 |
soup_session_send_message (session, msg);
|
|
rpm-build |
4f3c61 |
soup_test_assert_message_status (msg, SOUP_STATUS_OK);
|
|
rpm-build |
4f3c61 |
while (*events) {
|
|
rpm-build |
4f3c61 |
soup_test_assert (!*events,
|
|
rpm-build |
4f3c61 |
"Expected %s",
|
|
rpm-build |
4f3c61 |
event_name_from_abbrev (*events));
|
|
rpm-build |
4f3c61 |
events++;
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_object_unref (msg);
|
|
rpm-build |
4f3c61 |
soup_session_abort (session);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_connection_event_test_for_session (SoupSession *session)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupURI *proxy_uri;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " http\n");
|
|
rpm-build |
4f3c61 |
do_one_connection_event_test (session, HTTP_SERVER, "rRcCx");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (tls_available) {
|
|
rpm-build |
4f3c61 |
debug_printf (1, " https\n");
|
|
rpm-build |
4f3c61 |
do_one_connection_event_test (session, HTTPS_SERVER, "rRcCtTx");
|
|
rpm-build |
4f3c61 |
} else
|
|
rpm-build |
4f3c61 |
debug_printf (1, " https -- SKIPPING\n");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
proxy_uri = soup_uri_new (HTTP_PROXY);
|
|
rpm-build |
4f3c61 |
g_object_set (G_OBJECT (session),
|
|
rpm-build |
4f3c61 |
SOUP_SESSION_PROXY_URI, proxy_uri,
|
|
rpm-build |
4f3c61 |
NULL);
|
|
rpm-build |
4f3c61 |
soup_uri_free (proxy_uri);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " http with proxy\n");
|
|
rpm-build |
4f3c61 |
do_one_connection_event_test (session, HTTP_SERVER, "rRcCx");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (tls_available) {
|
|
rpm-build |
4f3c61 |
debug_printf (1, " https with proxy\n");
|
|
rpm-build |
4f3c61 |
do_one_connection_event_test (session, HTTPS_SERVER, "rRcCpPtTx");
|
|
rpm-build |
4f3c61 |
} else
|
|
rpm-build |
4f3c61 |
debug_printf (1, " https with proxy -- SKIPPING\n");
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_connection_event_test (void)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupSession *session;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
SOUP_TEST_SKIP_IF_NO_APACHE;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " Async session\n");
|
|
rpm-build |
4f3c61 |
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
|
|
rpm-build |
4f3c61 |
do_connection_event_test_for_session (session);
|
|
rpm-build |
4f3c61 |
soup_test_session_abort_unref (session);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " Sync session\n");
|
|
rpm-build |
4f3c61 |
session = soup_test_session_new (SOUP_TYPE_SESSION_SYNC, NULL);
|
|
rpm-build |
4f3c61 |
do_connection_event_test_for_session (session);
|
|
rpm-build |
4f3c61 |
soup_test_session_abort_unref (session);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
typedef struct {
|
|
rpm-build |
4f3c61 |
GMainLoop *loop;
|
|
rpm-build |
4f3c61 |
GIOStream *stream;
|
|
rpm-build |
4f3c61 |
GError *error;
|
|
rpm-build |
4f3c61 |
const char *events;
|
|
rpm-build |
4f3c61 |
} ConnectTestData;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
connect_progress (SoupSession *session, GSocketClientEvent event, GIOStream *connection, ConnectTestData *data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
soup_test_assert (*data->events == event_abbrevs[event],
|
|
rpm-build |
4f3c61 |
"Unexpected event: %s (expected %s)",
|
|
rpm-build |
4f3c61 |
event_names[event],
|
|
rpm-build |
4f3c61 |
event_name_from_abbrev (*data->events));
|
|
rpm-build |
4f3c61 |
data->events = data->events + 1;
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
connect_finished (SoupSession *session, GAsyncResult *result, ConnectTestData *data)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
data->stream = soup_session_connect_finish (session, result, &data->error);
|
|
rpm-build |
4f3c61 |
g_main_loop_quit (data->loop);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_one_connection_connect_test (SoupSession *session, SoupURI *uri, const char *response, const char *events)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
ConnectTestData data = { NULL, NULL, NULL, events };
|
|
rpm-build |
4f3c61 |
static const char *request = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n";
|
|
rpm-build |
4f3c61 |
gsize bytes = 0;
|
|
rpm-build |
4f3c61 |
char buffer[128];
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
data.loop = g_main_loop_new (NULL, FALSE);
|
|
rpm-build |
4f3c61 |
soup_session_connect_async (session, uri, NULL,
|
|
rpm-build |
4f3c61 |
(SoupSessionConnectProgressCallback)connect_progress,
|
|
rpm-build |
4f3c61 |
(GAsyncReadyCallback)connect_finished,
|
|
rpm-build |
4f3c61 |
&data);
|
|
rpm-build |
4f3c61 |
g_main_loop_run (data.loop);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_assert (G_IS_IO_STREAM (data.stream));
|
|
rpm-build |
4f3c61 |
g_assert_no_error (data.error);
|
|
rpm-build |
4f3c61 |
g_assert (g_output_stream_write_all (g_io_stream_get_output_stream (data.stream),
|
|
rpm-build |
4f3c61 |
request, strlen (request), &bytes, NULL, NULL));
|
|
rpm-build |
4f3c61 |
g_assert (g_input_stream_read_all (g_io_stream_get_input_stream (data.stream),
|
|
rpm-build |
4f3c61 |
buffer, sizeof (buffer), &bytes, NULL, NULL));
|
|
rpm-build |
4f3c61 |
buffer[strlen (response)] = '\0';
|
|
rpm-build |
4f3c61 |
g_assert_cmpstr (buffer, ==, response);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
while (*data.events) {
|
|
rpm-build |
4f3c61 |
soup_test_assert (!*data.events,
|
|
rpm-build |
4f3c61 |
"Expected %s",
|
|
rpm-build |
4f3c61 |
event_name_from_abbrev (*data.events));
|
|
rpm-build |
4f3c61 |
data.events++;
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_object_unref (data.stream);
|
|
rpm-build |
4f3c61 |
g_main_loop_unref (data.loop);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_one_connection_connect_fail_test (SoupSession *session, SoupURI *uri, GQuark domain, gint code, const char *events)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
ConnectTestData data = { NULL, NULL, NULL, events };
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
data.loop = g_main_loop_new (NULL, FALSE);
|
|
rpm-build |
4f3c61 |
soup_session_connect_async (session, uri, NULL,
|
|
rpm-build |
4f3c61 |
(SoupSessionConnectProgressCallback)connect_progress,
|
|
rpm-build |
4f3c61 |
(GAsyncReadyCallback)connect_finished,
|
|
rpm-build |
4f3c61 |
&data);
|
|
rpm-build |
4f3c61 |
g_main_loop_run (data.loop);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_assert (!data.stream);
|
|
rpm-build |
4f3c61 |
g_assert_error (data.error, domain, code);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
while (*data.events) {
|
|
rpm-build |
4f3c61 |
soup_test_assert (!*data.events,
|
|
rpm-build |
4f3c61 |
"Expected %s",
|
|
rpm-build |
4f3c61 |
event_name_from_abbrev (*data.events));
|
|
rpm-build |
4f3c61 |
data.events++;
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
static void
|
|
rpm-build |
4f3c61 |
do_connection_connect_test (void)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
SoupSession *session;
|
|
rpm-build |
4f3c61 |
SoupURI *http_uri;
|
|
rpm-build |
4f3c61 |
SoupURI *https_uri = NULL;
|
|
rpm-build |
4f3c61 |
SoupURI *ws_uri;
|
|
rpm-build |
4f3c61 |
SoupURI *wss_uri = NULL;
|
|
rpm-build |
4f3c61 |
SoupURI *file_uri;
|
|
rpm-build |
4f3c61 |
SoupURI *wrong_http_uri;
|
|
rpm-build |
4f3c61 |
SoupURI *proxy_uri;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
SOUP_TEST_SKIP_IF_NO_APACHE;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
|
|
rpm-build |
4f3c61 |
SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
|
|
rpm-build |
4f3c61 |
NULL);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " http\n");
|
|
rpm-build |
4f3c61 |
http_uri = soup_uri_new (HTTP_SERVER);
|
|
rpm-build |
4f3c61 |
do_one_connection_connect_test (session, http_uri,
|
|
rpm-build |
4f3c61 |
"HTTP/1.1 200 OK", "rRcCx");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (tls_available) {
|
|
rpm-build |
4f3c61 |
debug_printf (1, " https\n");
|
|
rpm-build |
4f3c61 |
https_uri = soup_uri_new (HTTPS_SERVER);
|
|
rpm-build |
4f3c61 |
do_one_connection_connect_test (session, https_uri,
|
|
rpm-build |
4f3c61 |
"HTTP/1.1 200 OK", "rRcCtTx");
|
|
rpm-build |
4f3c61 |
} else
|
|
rpm-build |
4f3c61 |
debug_printf (1, " https -- SKIPPING\n");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " ws\n");
|
|
rpm-build |
4f3c61 |
ws_uri = soup_uri_new (HTTP_SERVER);
|
|
rpm-build |
4f3c61 |
ws_uri->scheme = SOUP_URI_SCHEME_WS;
|
|
rpm-build |
4f3c61 |
do_one_connection_connect_test (session, ws_uri,
|
|
rpm-build |
4f3c61 |
"HTTP/1.1 200 OK", "rRcCx");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (tls_available) {
|
|
rpm-build |
4f3c61 |
debug_printf (1, " wss\n");
|
|
rpm-build |
4f3c61 |
wss_uri = soup_uri_new (HTTPS_SERVER);
|
|
rpm-build |
4f3c61 |
do_one_connection_connect_test (session, wss_uri,
|
|
rpm-build |
4f3c61 |
"HTTP/1.1 200 OK", "rRcCtTx");
|
|
rpm-build |
4f3c61 |
} else
|
|
rpm-build |
4f3c61 |
debug_printf (1, " wss -- SKIPPING\n");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " file\n");
|
|
rpm-build |
4f3c61 |
file_uri = soup_uri_new ("file:///foo/bar");
|
|
rpm-build |
4f3c61 |
do_one_connection_connect_fail_test (session, file_uri,
|
|
rpm-build |
4f3c61 |
G_RESOLVER_ERROR, G_RESOLVER_ERROR_NOT_FOUND,
|
|
rpm-build |
4f3c61 |
"r");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " wrong http (invalid port)\n");
|
|
rpm-build |
4f3c61 |
wrong_http_uri = soup_uri_new (HTTP_SERVER);
|
|
rpm-build |
4f3c61 |
wrong_http_uri->port = 1234;
|
|
rpm-build |
4f3c61 |
do_one_connection_connect_fail_test (session, wrong_http_uri,
|
|
rpm-build |
4f3c61 |
G_IO_ERROR, G_IO_ERROR_CONNECTION_REFUSED,
|
|
rpm-build |
4f3c61 |
"rRcr"); /* FIXME: why r again? GLib bug? */
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
proxy_uri = soup_uri_new (HTTP_PROXY);
|
|
rpm-build |
4f3c61 |
g_object_set (G_OBJECT (session),
|
|
rpm-build |
4f3c61 |
SOUP_SESSION_PROXY_URI, proxy_uri,
|
|
rpm-build |
4f3c61 |
NULL);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " http with proxy\n");
|
|
rpm-build |
4f3c61 |
do_one_connection_connect_test (session, http_uri,
|
|
rpm-build |
4f3c61 |
"HTTP/1.1 403 Forbidden", "rRcCx");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (tls_available) {
|
|
rpm-build |
4f3c61 |
debug_printf (1, " https with proxy\n");
|
|
rpm-build |
4f3c61 |
do_one_connection_connect_test (session, https_uri,
|
|
rpm-build |
4f3c61 |
"HTTP/1.1 200 OK", "rRcCpPtTx");
|
|
rpm-build |
4f3c61 |
} else
|
|
rpm-build |
4f3c61 |
debug_printf (1, " https with proxy -- SKIPPING\n");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
debug_printf (1, " ws with proxy\n");
|
|
rpm-build |
4f3c61 |
do_one_connection_connect_test (session, ws_uri,
|
|
rpm-build |
4f3c61 |
"HTTP/1.1 403 Forbidden", "rRcCx");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
if (tls_available) {
|
|
rpm-build |
4f3c61 |
debug_printf (1, " wss with proxy\n");
|
|
rpm-build |
4f3c61 |
do_one_connection_connect_test (session, wss_uri,
|
|
rpm-build |
4f3c61 |
"HTTP/1.1 200 OK", "rRcCpPtTx");
|
|
rpm-build |
4f3c61 |
} else
|
|
rpm-build |
4f3c61 |
debug_printf (1, " wss with proxy -- SKIPPING\n");
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_uri_free (http_uri);
|
|
rpm-build |
4f3c61 |
if (https_uri)
|
|
rpm-build |
4f3c61 |
soup_uri_free (https_uri);
|
|
rpm-build |
4f3c61 |
soup_uri_free (ws_uri);
|
|
rpm-build |
4f3c61 |
if (wss_uri)
|
|
rpm-build |
4f3c61 |
soup_uri_free (wss_uri);
|
|
rpm-build |
4f3c61 |
soup_uri_free (file_uri);
|
|
rpm-build |
4f3c61 |
soup_uri_free (wrong_http_uri);
|
|
rpm-build |
4f3c61 |
soup_uri_free (proxy_uri);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_test_session_abort_unref (session);
|
|
rpm-build |
4f3c61 |
}
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
int
|
|
rpm-build |
4f3c61 |
main (int argc, char **argv)
|
|
rpm-build |
4f3c61 |
{
|
|
rpm-build |
4f3c61 |
int ret;
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
test_init (argc, argv, NULL);
|
|
rpm-build |
4f3c61 |
apache_init ();
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
server = soup_test_server_new (SOUP_TEST_SERVER_IN_THREAD);
|
|
rpm-build |
4f3c61 |
soup_server_add_handler (server, NULL, server_callback, "http", NULL);
|
|
rpm-build |
4f3c61 |
base_uri = soup_test_server_get_uri (server, "http", NULL);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
g_test_add_func ("/connection/content-length-framing", do_content_length_framing_test);
|
|
rpm-build |
4f3c61 |
g_test_add_func ("/connection/persistent-connection-timeout", do_persistent_connection_timeout_test);
|
|
rpm-build |
4f3c61 |
g_test_add_func ("/connection/max-conns", do_max_conns_test);
|
|
rpm-build |
4f3c61 |
g_test_add_func ("/connection/non-persistent", do_non_persistent_connection_test);
|
|
rpm-build |
4f3c61 |
g_test_add_func ("/connection/non-idempotent", do_non_idempotent_connection_test);
|
|
rpm-build |
4f3c61 |
g_test_add_func ("/connection/state", do_connection_state_test);
|
|
rpm-build |
4f3c61 |
g_test_add_func ("/connection/event", do_connection_event_test);
|
|
rpm-build |
4f3c61 |
g_test_add_func ("/connection/connect", do_connection_connect_test);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
ret = g_test_run ();
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
soup_uri_free (base_uri);
|
|
rpm-build |
4f3c61 |
soup_test_server_quit_unref (server);
|
|
rpm-build |
4f3c61 |
|
|
rpm-build |
4f3c61 |
test_cleanup ();
|
|
rpm-build |
4f3c61 |
return ret;
|
|
rpm-build |
4f3c61 |
}
|