-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
httpd_req_get_url_query_str
does not work with websockets (IDFGH-10685)
#11911
Comments
httpd_req_get_url_query_str
does not work with websocketshttpd_req_get_url_query_str
does not work with websockets (IDFGH-10685)
Here's roughly the code that I'm using: static esp_err_t ws_get_identifier(httpd_req_t* req, char* dest, size_t dest_size) {
if (req == NULL) {
return ESP_OK;
}
char buffer[128] = {0};
size_t buffer_length = 0;
// first check query string
buffer_length = httpd_req_get_url_query_len(req);
if (buffer_length > sizeof(buffer)) {
// TODO: off by 1 err here?
ESP_LOGW(TAG, "query length exceeds buffer length");
return ESP_ERR_INVALID_SIZE;
}
if (buffer_length > 0) {
ESP_RETURN_ON_ERROR(httpd_req_get_url_query_str(req, buffer, buffer_length + 1), TAG, "cannot get query string");
ESP_LOGI(TAG, "query string = '%s'", buffer); // this is printing "query string = ''"
}
return ESP_OK;
} |
Ya it's pretty annoying and should be improved imo. I use a workaround using the user_ctx to store the uri.
It's not super easy to fix this in ESP-IDF. The URI is dynamic. We only know the URI when the websocket is first opened because it is sent in the HTTP request header. ESP-IDF would need to store this dynamic URI on the heap somewhere, and then free it when the websocket is closed. If you were to open a PR to fix it, the most natural place to store this would be in the
|
@kevinhikaruevans Any update for this issue. I think @chipweinberger solution could solve your issue. |
I found an alternative work around. I think This behavior doesn't appear to be documented too. |
Answers checklist.
IDF version.
v5.0.0
Operating System used.
Linux
How did you build your project?
Other (please specify in More Information)
If you are using Windows, please specify command line type.
None
Development Kit.
esp32-s3-devkitc-1
Power Supply used.
USB
What is the expected behavior?
If it returns
ESP_OK
, it should write the query string to the buffer passed in.If it is not supported with websockets, it should return an error code.
What is the actual behavior?
It does not write anything to the passed buffer (or maybe it's writing an empty string).
Steps to reproduce.
/ws?something=abcd
httpd_req_get_url_query_len(req) > 0
andhttpd_req_get_url_query_str == ESP_OK
, but the query string is emptyDebug Logs.
More Information.
Edit: This only seems to happen when receiving a frame. Prior to the handshake, it seems that the query string is accessible.
The text was updated successfully, but these errors were encountered: