[libsoup/websocket: 3/11] soup-message-server-io: handle "CONNECT" syntax when parsing requests



commit 9aa88aa19203c44d2c146d52181f24472fa253b3
Author: Dan Winship <danw gnome org>
Date:   Sun Jun 8 15:13:20 2014 -0400

    soup-message-server-io: handle "CONNECT" syntax when parsing requests

 libsoup/soup-message-server-io.c |   28 +++++++++++++++++++++++++++-
 1 files changed, 27 insertions(+), 1 deletions(-)
---
diff --git a/libsoup/soup-message-server-io.c b/libsoup/soup-message-server-io.c
index 683a4ee..35b544c 100644
--- a/libsoup/soup-message-server-io.c
+++ b/libsoup/soup-message-server-io.c
@@ -9,6 +9,7 @@
 #include "config.h"
 #endif
 
+#include <stdlib.h>
 #include <string.h>
 
 #include <glib/gi18n-lib.h>
@@ -18,6 +19,28 @@
 #include "soup-misc-private.h"
 #include "soup-socket-private.h"
 
+static SoupURI *
+parse_connect_authority (const char *req_path)
+{
+       SoupURI *uri;
+       char *fake_uri;
+
+       fake_uri = g_strdup_printf ("http://%s";, req_path);
+       uri = soup_uri_new (fake_uri);
+       g_free (fake_uri);
+
+       if (uri->user || uri->password ||
+           uri->query || uri->fragment ||
+           !uri->host ||
+           (uri->port == 0) ||
+           (strcmp (uri->path, "/") != 0)) {
+               soup_uri_free (uri);
+               return NULL;
+       }
+
+       return uri;
+}
+
 static guint
 parse_request_headers (SoupMessage *msg, char *headers, guint headers_len,
                       SoupEncoding *encoding, gpointer sock, GError **error)
@@ -74,8 +97,11 @@ parse_request_headers (SoupMessage *msg, char *headers, guint headers_len,
                if (uri)
                        soup_uri_set_path (uri, "*");
                g_free (url);
+       } else if (msg->method == SOUP_METHOD_CONNECT) {
+               /* Authority */
+               uri = parse_connect_authority (req_path);
        } else if (*req_path != '/') {
-               /* Must be an absolute URI */
+               /* Absolute URI */
                uri = soup_uri_new (req_path);
        } else if (req_host) {
                url = g_strdup_printf ("%s://%s%s",


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]