I want to create a small helper function
Code: Select all
/**
* @param [in] req
* @param [in] key The header key on which we want the value back
* @param [out] buf The header value written to.
**/
esp_err_t get_header(httpd_req_t *req, const char *key, char *buf) {
size_t buf_len = httpd_req_get_hdr_value_len(req, key) + 1;
if (buf_len > 1) {
buf = new char[buf_len];
if (!buf) {
ESP_LOGE(TAG, "No enough memory for basic authorization");
return ESP_ERR_NO_MEM;
}
return httpd_req_get_hdr_value_str(req, key, buf, buf_len);
}
return ESP_ERR_NOT_FOUND ;
}
Code: Select all
char *header_value{nullptr};
esp_err_t status = get_header(req, "Authorization", header_value);
// use it outside
if (header_value ..... // makes a condition on the header value
Or as a sd::string. Whatever is more performant.
Thanks for your help.