Page 1 of 1

esp_http_server help request

Posted: Sat Oct 27, 2018 6:57 pm
by chegewara
Few days ago my code has been working just fine, but today i am having very strange behavior. I am trying to send base64 data with Content-Type set to image/jpeg but my browser is receiving 2 headers with key Content-Type (image/jpeg and text/html). This is my code to set header:

Code: Select all

	httpd_resp_set_hdr(req, "Content-Type", "image/jpeg");
	httpd_resp_send(req, (const char*)data->base64_data, data->base64_size);
Browser response headers:

Code: Select all

HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 20480
Content-Type: image/jpeg
Just checked and for text/json i am also getting two Content-Type headers:

Code: Select all

Content-Length: 27168
Content-Type: text/html
Content-Type: text/json

Re: esp_http_server help request

Posted: Sat Oct 27, 2018 8:42 pm
by chegewara
Using

Code: Select all

httpd_resp_set_type 
to set content type fixes my issue, but this looks like small bug.

Re: esp_http_server help request

Posted: Mon Oct 29, 2018 5:29 am
by ESP_Anurag
As per the API reference documentation, `httpd_resp_set_hdr()` must be used only for setting additional headers other than `Content-Type` and `Content-Length`. The `Content-Type` field must be set using only `httpd_resp_set_type()`, else it will cause unwanted behavior.

I will update the API reference to make this more clear, so as to not cause confusion and inconvenience for the users in future.