esp_http_server help request

chegewara
Posts: 2378
Joined: Wed Jun 14, 2017 9:00 pm

esp_http_server help request

Postby chegewara » Sat Oct 27, 2018 6:57 pm

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

chegewara
Posts: 2378
Joined: Wed Jun 14, 2017 9:00 pm

Re: esp_http_server help request

Postby chegewara » Sat Oct 27, 2018 8:42 pm

Using

Code: Select all

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

ESP_Anurag
Posts: 19
Joined: Fri Aug 31, 2018 5:37 am

Re: esp_http_server help request

Postby ESP_Anurag » Mon Oct 29, 2018 5:29 am

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.

Who is online

Users browsing this forum: No registered users and 94 guests