From 271e6c4c9c57ca6715c1435a71fe3974cd2b18b3 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Wed, 25 Sep 2019 15:30:01 +0200 Subject: [PATCH] websocket_client: fix URI parsing to include also query part in websocket connection path closes https://github.com/espressif/esp-idf/issues/4090 --- .../esp_websocket_client/esp_websocket_client.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/components/esp_websocket_client/esp_websocket_client.c b/components/esp_websocket_client/esp_websocket_client.c index dc7333419..6352ef223 100644 --- a/components/esp_websocket_client/esp_websocket_client.c +++ b/components/esp_websocket_client/esp_websocket_client.c @@ -382,9 +382,16 @@ esp_err_t esp_websocket_client_set_uri(esp_websocket_client_handle_t client, con } - if (puri.field_data[UF_PATH].len) { + if (puri.field_data[UF_PATH].len || puri.field_data[UF_QUERY].len) { free(client->config->path); - asprintf(&client->config->path, "%.*s", puri.field_data[UF_PATH].len, uri + puri.field_data[UF_PATH].off); + if (puri.field_data[UF_QUERY].len == 0) { + asprintf(&client->config->path, "%.*s", puri.field_data[UF_PATH].len, uri + puri.field_data[UF_PATH].off); + } else if (puri.field_data[UF_PATH].len == 0) { + asprintf(&client->config->path, "/?%.*s", puri.field_data[UF_QUERY].len, uri + puri.field_data[UF_QUERY].off); + } else { + asprintf(&client->config->path, "%.*s?%.*s", puri.field_data[UF_PATH].len, uri + puri.field_data[UF_PATH].off, + puri.field_data[UF_QUERY].len, uri + puri.field_data[UF_QUERY].off); + } ESP_WS_CLIENT_MEM_CHECK(TAG, client->config->path, return ESP_ERR_NO_MEM); } if (puri.field_data[UF_PORT].off) {