aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-06-25 21:54:16 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-06-25 21:54:16 +0200
commitbe1e424e172928e39f2d6e8edf681d58b653f862 (patch)
treef1afea6725dfbe2382f3768665c6f17f992e5e95
parenta16a7940dd0a475f6badd1ddbfb3bc784d2dd92a (diff)
downloadjson-rpc-shell-be1e424e172928e39f2d6e8edf681d58b653f862.tar.gz
json-rpc-shell-be1e424e172928e39f2d6e8edf681d58b653f862.tar.xz
json-rpc-shell-be1e424e172928e39f2d6e8edf681d58b653f862.zip
WS: include the part after '?' in the query
-rw-r--r--json-rpc-shell.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/json-rpc-shell.c b/json-rpc-shell.c
index 7d91853..c5142f6 100644
--- a/json-rpc-shell.c
+++ b/json-rpc-shell.c
@@ -1294,6 +1294,7 @@ backend_ws_connect (struct app_context *ctx, struct error **e)
self->url.field_data[UF_SCHEMA].off,
self->url.field_data[UF_SCHEMA].len);
bool use_tls = !strcasecmp_ascii (url_schema, "wss");
+ free (url_schema);
char *url_host = xstrndup (self->endpoint +
self->url.field_data[UF_HOST].off,
@@ -1304,10 +1305,18 @@ backend_ws_connect (struct app_context *ctx, struct error **e)
self->url.field_data[UF_PORT].len)
: xstrdup (use_tls ? "443" : "80");
- // FIXME: should include "?UF_QUERY" as well, if present
- char *url_path = xstrndup (self->endpoint +
+ struct str url_path;
+ str_init (&url_path);
+ str_append_data (&url_path, self->endpoint +
self->url.field_data[UF_PATH].off,
self->url.field_data[UF_PATH].len);
+ if (self->url.field_set & (1 << UF_QUERY))
+ {
+ str_append_c (&url_path, '?');
+ str_append_data (&url_path, self->endpoint +
+ self->url.field_data[UF_QUERY].off,
+ self->url.field_data[UF_QUERY].len);
+ }
if (!backend_ws_establish_connection (ctx, url_host, url_port, e))
goto fail_1;
@@ -1332,7 +1341,7 @@ backend_ws_connect (struct app_context *ctx, struct error **e)
struct str request;
str_init (&request);
- str_append_printf (&request, "GET %s HTTP/1.1\r\n", url_path);
+ str_append_printf (&request, "GET %s HTTP/1.1\r\n", url_path.str);
// TODO: omit the port if it's the default (check RFC for "SHOULD" or ...)
str_append_printf (&request, "Host: %s:%s\r\n", url_host, url_port);
str_append_printf (&request, "Upgrade: websocket\r\n");
@@ -1395,10 +1404,9 @@ fail_2:
self->server_fd = -1;
}
fail_1:
- free (url_schema);
free (url_host);
free (url_port);
- free (url_path);
+ str_free (&url_path);
return result;
}