Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket client library does not handle subprotocols (IDFGH-1644) #3893

Closed
fordosg opened this issue Aug 7, 2019 · 1 comment
Closed

Websocket client library does not handle subprotocols (IDFGH-1644) #3893

fordosg opened this issue Aug 7, 2019 · 1 comment
Assignees

Comments

@fordosg
Copy link

fordosg commented Aug 7, 2019

Environment

  • IDF version: v4.0-dev-1381-g6fe853a2c

Problem Description

Hi all,

With the new Websockets library can not set subprotocol header for websocket initialization.

One possible solution: extend the configuration with subprotocol variable.

Configuration storage code (components/esp_websocket_client/esp_websocket_client.c; from line 76):

typedef struct {
    int                         task_stack;
    int                         task_prio;
    char                        *uri;
    char                        *host;
    char                        *path;
    char                        *scheme;
    char                        *username;
    char                        *password;
    int                         port;
    bool                        auto_reconnect;
    void                        *user_context;
    int                         network_timeout_ms;
    char			*subprotocol;
} websocket_config_storage_t;

Configuration processor code (components/esp_websocket_client/esp_websocket_client.c; from line 170):

    if (config->path) {
        free(cfg->path);
        cfg->path = strdup(config->path);
        ESP_WS_CLIENT_MEM_CHECK(TAG, cfg->path, return ESP_ERR_NO_MEM);
    }
    if (config->subprotocol) {
        free(cfg->subprotocol);
        cfg->subprotocol = strdup(config->subprotocol);
        ESP_WS_CLIENT_MEM_CHECK(TAG, cfg->subprotocol, return ESP_ERR_NO_MEM);
    }

    cfg->network_timeout_ms = WEBSOCKET_NETWORK_TIMEOUT_MS;
    cfg->user_context = config->user_context;
    cfg->auto_reconnect = true;

Client intialization code (components/esp_websocket_client/esp_websocket_client.c; from line 430):

if (client->transport == NULL) {
                    ESP_LOGE(TAG, "There are no transport");
                    client->run = false;
                    break;
                }

		esp_transport_ws_set_path(client->transport, client->config->path);
		esp_transport_ws_set_subprotocol(client->transport, client->config->subprotocol);

                if (esp_transport_connect(client->transport,
                                          client->config->host,
                                          client->config->port,
                                          client->config->network_timeout_ms) < 0) {
                    ESP_LOGE(TAG, "Error transport connect");
                    esp_websocket_client_abort_connection(client);
                    break;
                }

Regards,

@github-actions github-actions bot changed the title Websocket client library does not handle subprotocols Websocket client library does not handle subprotocols (IDFGH-1644) Aug 7, 2019
@david-cermak
Copy link
Collaborator

Thank you very much for posting these websocket realated issues as well as the suggested fixes. They make perfect sense.

Will be fixed, same applies for #3890 #3891 #3892 too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants