diff options
author | Dan Winship <danw@gnome.org> | 2012-01-30 18:55:40 -0500 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2012-01-30 18:57:31 -0500 |
commit | 5c3b01a9da2390fdebbea5131cf80a96a9c8f67f (patch) | |
tree | 92a0d56ce178682eb0edce6a2f2164137b8c54eb /tests/requester-test.c | |
parent | 9c89179ca1ee1476da7b763702e1d72b3cbd3242 (diff) | |
download | libsoup-5c3b01a9da2390fdebbea5131cf80a96a9c8f67f.tar.gz libsoup-5c3b01a9da2390fdebbea5131cf80a96a9c8f67f.tar.bz2 libsoup-5c3b01a9da2390fdebbea5131cf80a96a9c8f67f.zip |
requester-test: add some more tests
Make sure that content-sniffing and redirections work
Diffstat (limited to 'tests/requester-test.c')
-rw-r--r-- | tests/requester-test.c | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/tests/requester-test.c b/tests/requester-test.c index c5565405..ad679fce 100644 --- a/tests/requester-test.c +++ b/tests/requester-test.c @@ -36,14 +36,26 @@ get_index (void) response = soup_buffer_new (SOUP_MEMORY_TAKE, contents, length); } +#define REDIRECT_HTML_BODY "<html><body>Try again</body></html>\r\n" + static void server_callback (SoupServer *server, SoupMessage *msg, const char *path, GHashTable *query, SoupClientContext *context, gpointer data) { + if (strcmp (path, "/") != 0) { + soup_message_set_redirect (msg, SOUP_STATUS_FOUND, "/"); + /* Make the response HTML so if we sniff that instead of the + * real body, we'll notice. + */ + soup_message_set_response (msg, "text/html", + SOUP_MEMORY_STATIC, + REDIRECT_HTML_BODY, + strlen (REDIRECT_HTML_BODY)); + return; + } + soup_message_set_status (msg, SOUP_STATUS_OK); - soup_message_set_response (msg, "text/plain", - SOUP_MEMORY_STATIC, NULL, 0); soup_message_body_append_buffer (msg->response_body, response); } @@ -81,10 +93,11 @@ test_sent (GObject *source, GAsyncResult *res, gpointer user_data) GInputStream *stream; GError *error = NULL; SoupMessage *msg; + const char *content_type; stream = soup_request_send_finish (SOUP_REQUEST (source), res, &error); if (!stream) { - debug_printf (1, " send_async failed: %s", error->message); + debug_printf (1, " send_async failed: %s\n", error->message); errors++; g_main_loop_quit (loop); return; @@ -92,7 +105,7 @@ test_sent (GObject *source, GAsyncResult *res, gpointer user_data) msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (source)); if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) { - debug_printf (1, " GET failed: %d %s", msg->status_code, + debug_printf (1, " GET failed: %d %s\n", msg->status_code, msg->reason_phrase); errors++; g_main_loop_quit (loop); @@ -100,6 +113,13 @@ test_sent (GObject *source, GAsyncResult *res, gpointer user_data) } g_object_unref (msg); + content_type = soup_request_get_content_type (SOUP_REQUEST (source)); + if (g_strcmp0 (content_type, "text/plain") != 0) { + debug_printf (1, " failed to sniff Content-Type: got %s\n", + content_type ? content_type : "(NULL)"); + errors++; + } + g_input_stream_read_async (stream, buf, sizeof (buf), G_PRIORITY_DEFAULT, NULL, test_read_ready, body); @@ -115,6 +135,7 @@ do_test_for_thread_and_context (SoupSession *session, const char *uri) requester = soup_requester_new (); soup_session_add_feature (session, SOUP_SESSION_FEATURE (requester)); g_object_unref (requester); + soup_session_add_feature_by_type (session, SOUP_TYPE_CONTENT_SNIFFER); body = g_string_new (NULL); @@ -201,7 +222,7 @@ main (int argc, char **argv) server = soup_test_server_new (TRUE); soup_server_add_handler (server, NULL, server_callback, NULL, NULL); - uri = g_strdup_printf ("http://127.0.0.1:%u/", soup_server_get_port (server)); + uri = g_strdup_printf ("http://127.0.0.1:%u/foo", soup_server_get_port (server)); do_simple_test (uri); do_thread_test (uri); |