summaryrefslogtreecommitdiff
path: root/tests/misc-test.c
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2009-08-04 19:34:30 -0400
committerDan Winship <danw@gnome.org>2009-08-09 10:31:54 -0400
commit280dc8568d9ebe9fb16fb13b2272169e968b3e49 (patch)
tree799dce34ba2e5c023ea45ba2cf5807a9fe0341f3 /tests/misc-test.c
parent8cc54925bbec130acd796d96363ad31223c3a962 (diff)
downloadlibsoup-280dc8568d9ebe9fb16fb13b2272169e968b3e49.tar.gz
Support "OPTIONS *" in SoupServer
Update soup-message-server-io.c to allow "*" in a Request-Line, and update SoupServer and SoupAuthDomain methods and docs to deal with it. For backward-compatibility, requests to "*" are NOT passed to the default handler; you must explicitly register a handler for "*". http://bugzilla.gnome.org/show_bug.cgi?id=590751
Diffstat (limited to 'tests/misc-test.c')
-rw-r--r--tests/misc-test.c95
1 files changed, 94 insertions, 1 deletions
diff --git a/tests/misc-test.c b/tests/misc-test.c
index 70415d3a..e6944777 100644
--- a/tests/misc-test.c
+++ b/tests/misc-test.c
@@ -18,6 +18,7 @@
#include "test-utils.h"
+SoupServer *server;
SoupURI *base_uri;
static gboolean
@@ -34,6 +35,16 @@ server_callback (SoupServer *server, SoupMessage *msg,
{
SoupURI *uri = soup_message_get_uri (msg);
+ soup_message_headers_append (msg->response_headers,
+ "X-Handled-By", "server_callback");
+
+ if (!strcmp (path, "*")) {
+ debug_printf (1, " default server_callback got request for '*'!\n");
+ errors++;
+ soup_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR);
+ return;
+ }
+
if (msg->method != SOUP_METHOD_GET) {
soup_message_set_status (msg, SOUP_STATUS_NOT_IMPLEMENTED);
return;
@@ -62,6 +73,29 @@ server_callback (SoupServer *server, SoupMessage *msg,
}
}
+static void
+server_star_callback (SoupServer *server, SoupMessage *msg,
+ const char *path, GHashTable *query,
+ SoupClientContext *context, gpointer data)
+{
+ soup_message_headers_append (msg->response_headers,
+ "X-Handled-By", "star_callback");
+
+ if (strcmp (path, "*") != 0) {
+ debug_printf (1, " server_star_callback got request for '%s'!\n", path);
+ errors++;
+ soup_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR);
+ return;
+ }
+
+ if (msg->method != SOUP_METHOD_OPTIONS) {
+ soup_message_set_status (msg, SOUP_STATUS_METHOD_NOT_ALLOWED);
+ return;
+ }
+
+ soup_message_set_status (msg, SOUP_STATUS_OK);
+}
+
/* Host header handling: client must be able to override the default
* value, server must be able to recognize different Host values.
* #539803.
@@ -283,10 +317,68 @@ do_msg_reuse_test (void)
g_free (signal_ids);
}
+static void
+do_star_test (void)
+{
+ SoupSession *session;
+ SoupMessage *msg;
+ SoupURI *star_uri;
+ const char *handled_by;
+
+ debug_printf (1, "\nOPTIONS *\n");
+
+ session = soup_test_session_new (SOUP_TYPE_SESSION_SYNC, NULL);
+ star_uri = soup_uri_copy (base_uri);
+ soup_uri_set_path (star_uri, "*");
+
+ debug_printf (1, " Testing with no handler\n");
+ msg = soup_message_new_from_uri ("OPTIONS", star_uri);
+ soup_session_send_message (session, msg);
+
+ if (msg->status_code != SOUP_STATUS_NOT_FOUND) {
+ debug_printf (1, " Unexpected response: %d %s\n",
+ msg->status_code, msg->reason_phrase);
+ errors++;
+ }
+ handled_by = soup_message_headers_get_one (msg->response_headers,
+ "X-Handled-By");
+ if (handled_by) {
+ /* Should have been rejected by SoupServer directly */
+ debug_printf (1, " Message reached handler '%s'\n",
+ handled_by);
+ errors++;
+ }
+ g_object_unref (msg);
+
+ soup_server_add_handler (server, "*", server_star_callback, NULL, NULL);
+
+ debug_printf (1, " Testing with handler\n");
+ msg = soup_message_new_from_uri ("OPTIONS", star_uri);
+ soup_session_send_message (session, msg);
+
+ if (msg->status_code != SOUP_STATUS_OK) {
+ debug_printf (1, " Unexpected response: %d %s\n",
+ msg->status_code, msg->reason_phrase);
+ errors++;
+ }
+ handled_by = soup_message_headers_get_one (msg->response_headers,
+ "X-Handled-By");
+ if (!handled_by) {
+ debug_printf (1, " Message did not reach handler!\n");
+ errors++;
+ } else if (strcmp (handled_by, "star_callback") != 0) {
+ debug_printf (1, " Message reached incorrect handler '%s'\n",
+ handled_by);
+ errors++;
+ }
+ g_object_unref (msg);
+
+ soup_test_session_abort_unref (session);
+}
+
int
main (int argc, char **argv)
{
- SoupServer *server;
SoupAuthDomain *auth_domain;
test_init (argc, argv, NULL);
@@ -307,6 +399,7 @@ main (int argc, char **argv)
do_host_test ();
do_callback_unref_test ();
do_msg_reuse_test ();
+ do_star_test ();
soup_uri_free (base_uri);