client redirect: make sure there is a leading / on path
authorAndy Green <andy@warmcat.com>
Fri, 10 Feb 2017 03:00:38 +0000 (11:00 +0800)
committerAndy Green <andy@warmcat.com>
Fri, 10 Feb 2017 03:00:38 +0000 (11:00 +0800)
lib/client-handshake.c
lib/client.c

index 306c392..9d4b573 100644 (file)
@@ -372,9 +372,11 @@ failed1:
  * host:       host header to send to the new server
  */
 LWS_VISIBLE struct lws *
-lws_client_reset(struct lws *wsi, int ssl, const char *address, int port, const char *path, const char *host)
+lws_client_reset(struct lws *wsi, int ssl, const char *address, int port,
+                const char *path, const char *host)
 {
        char origin[300] = "", protocol[300] = "", method[32] = "", *p;
+
        if (wsi->u.hdr.redirects == 3) {
                lwsl_err("%s: Too many redirects\n", __func__);
                return NULL;
@@ -402,7 +404,8 @@ lws_client_reset(struct lws *wsi, int ssl, const char *address, int port, const
        if (p)
                strncpy(method, p, sizeof(method) - 1);
 
-       lwsl_notice("redirect ads='%s', port=%d, path='%s', ssl = %d\n", address, port, path, ssl);
+       lwsl_debug("redirect ads='%s', port=%d, path='%s', ssl = %d\n",
+                  address, port, path, ssl);
 
        /* close the connection by hand */
 
@@ -420,9 +423,6 @@ lws_client_reset(struct lws *wsi, int ssl, const char *address, int port, const
        if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS, address))
                return NULL;
 
-       if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_URI, path))
-               return NULL;
-
        if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_HOST, host))
                return NULL;
 
@@ -439,6 +439,11 @@ lws_client_reset(struct lws *wsi, int ssl, const char *address, int port, const
                                          method))
                        return NULL;
 
+       origin[0] = '/';
+       strncpy(&origin[1], path, sizeof(origin) - 2);
+       if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_URI, origin))
+               return NULL;
+
        return lws_client_connect_2(wsi);
 }
 
index 4ffb1fa..4cbe2d5 100755 (executable)
@@ -483,8 +483,6 @@ lws_client_interpret_server_handshake(struct lws *wsi)
                if (!strcmp(prot, "wss") || !strcmp(prot, "https"))
                        ssl = 1;
 
-               lwsl_notice("ssl %d %s\n", ssl, prot);
-
                if (!lws_client_reset(wsi, ssl, ads, port, path, ads)) {
                        lwsl_err("Redirect failed\n");
                        cce = "HS: Redirect failed";