HTTP Client: Content length -1, but receiving data

jubueche
Posts: 32
Joined: Sat Jan 19, 2019 4:03 pm

HTTP Client: Content length -1, but receiving data

Postby jubueche » Fri Feb 01, 2019 3:01 pm

I am trying to read a simple .json from a webpage hosted on azure and proxied by cloudflare. I am running this script on my ESP32:

Code: Select all

static void http_download_chunk()
{
    esp_http_client_config_t config = {
        .url = "https://www.chaze-sports.com/firmware.json",
        .event_handler = _http_event_handler,
    };
    esp_http_client_handle_t client = esp_http_client_init(&config);
    esp_err_t err = esp_http_client_perform(client);

    if (err == ESP_OK) {
        ESP_LOGI(TAG, "HTTP chunk encoding Status = %d, content_length = %d",
                esp_http_client_get_status_code(client),
                esp_http_client_get_content_length(client));
    } else {
        ESP_LOGE(TAG, "Error perform http request %s", esp_err_to_name(err));
    }
    esp_http_client_cleanup(client);
}
I omitted the rest as it is not necessary.
This is my debug-level output:

Code: Select all

D (5244) HTTP_CLIENT: Begin connect to: https://www.chaze-sports.com:443
D (5254) esp-tls: host:www.chaze-sports.com: strlen 20
D (5284) esp-tls: handshake in progress...
D (5354) phy_init: wifi mac time delta: 3323
D (5564) phy_init: wifi mac time delta: 98410
D (5664) phy_init: wifi mac time delta: 98335
D (5764) phy_init: wifi mac time delta: 98347
D (5874) phy_init: wifi mac time delta: 98309
D (5974) phy_init: wifi mac time delta: 98317
D (6074) phy_init: wifi mac time delta: 98338
D (6124) phy_init: wifi mac time delta: 47101
D (6194) HTTP_CLIENT: HTTP_EVENT_ON_CONNECTED
D (6194) HTTP_CLIENT: Write header[3]: GET /firmware.json HTTP/1.1
User-Agent: ESP32 HTTP Client/1.0
Host: www.chaze-sports.com
Content-Length: 0


D (6384) phy_init: wifi mac time delta: 76331
D (6394) HTTP_CLIENT: on_message_begin
D (6394) HTTP_CLIENT: HEADER=Date:Fri, 01 Feb 2019 14:10:22 GMT
D (6394) HTTP_CLIENT: HTTP_EVENT_ON_HEADER, key=Date, value=Fri, 01 Feb 2019 14:10:22 GMT
D (6404) HTTP_CLIENT: HEADER=Content-Type:application/json; charset=UTF-8
D (6404) HTTP_CLIENT: HTTP_EVENT_ON_HEADER, key=Content-Type, value=application/json; charset=UTF-8
D (6414) HTTP_CLIENT: HEADER=Transfer-Encoding:chunked
D (6424) HTTP_CLIENT: HTTP_EVENT_ON_HEADER, key=Transfer-Encoding, value=chunked
D (6424) HTTP_CLIENT: HEADER=Connection:keep-alive
D (6434) HTTP_CLIENT: HTTP_EVENT_ON_HEADER, key=Connection, value=keep-alive
D (6444) HTTP_CLIENT: HEADER=Set-Cookie:__cfduid=d9a3936dd427e8858e47a0c9e6428d3c21549030221; expires=Sat, 01-Feb-20 14:10:21 GMT; path=/; domain=.chaze-sports.com; HttpOnly; Secure
D (6454) HTTP_CLIENT: HTTP_EVENT_ON_HEADER, key=Set-Cookie, value=__cfduid=d9a3936dd427e8858e47a0c9e6428d3c21549030221; expires=Sat, 01-Feb-20 14:10:21 GMT; path=/; domain=.chaze-sports.com; HttpOnly; Secure
D (6474) HTTP_CLIENT: HEADER=Cache-Control:public, max-age=0
D (6484) HTTP_CLIENT: HTTP_EVENT_ON_HEADER, key=Cache-Control, value=public, max-age=0
D (6484) phy_init: wifi mac time delta: 42967
D (6494) HTTP_CLIENT: HEADER=Last-Modified:Thu, 31 Jan 2019 10:59:40 GMT
D (6504) HTTP_CLIENT: HTTP_EVENT_ON_HEADER, key=Last-Modified, value=Thu, 31 Jan 2019 10:59:40 GMT
D (6514) HTTP_CLIENT: HEADER=ETag:W/"6a-168a3907816"
D (6514) HTTP_CLIENT: HTTP_EVENT_ON_HEADER, key=ETag, value=W/"6a-168a3907816"
D (6524) HTTP_CLIENT: HEADER=Vary:Accept-Encoding
D (6524) HTTP_CLIENT: HTTP_EVENT_ON_HEADER, key=Vary, value=Accept-Encoding
D (6534) HTTP_CLIENT: HEADER=X-Powered-By:Express
D (6534) HTTP_CLIENT: HTTP_EVENT_ON_HEADER, key=X-Powered-By, value=Express
D (6544) HTTP_CLIENT: HEADER=X-Powered-By:ASP.NET
D (6554) HTTP_CLIENT: HTTP_EVENT_ON_HEADER, key=X-Powered-By, value=ASP.NET
D (6554) HTTP_CLIENT: HEADER=Set-Cookie:ARRAffinity=14683
D (6564) HTTP_CLIENT: HTTP_EVENT_ON_HEADER, key=Set-Cookie, value=ARRAffinity=14683
D (6574) HTTP_CLIENT: HEADER=Expect-CT:max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
D (6584) HTTP_CLIENT: HTTP_EVENT_ON_HEADER, key=Expect-CT, value=max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
D (6594) HTTP_CLIENT: HEADER=Server:cloudflare
D (6604) HTTP_CLIENT: HTTP_EVENT_ON_HEADER, key=Server, value=cloudflare
D (6604) HTTP_CLIENT: HEADER=CF-RAY:4a2500471e15c4dd-DUS
D (6614) HTTP_CLIENT: HTTP_EVENT_ON_HEADER, key=CF-RAY, value=4a2500471e15c4dd-DUS
D (6624) HTTP_CLIENT: http_on_headers_complete, status=200, offset=770, nread=770
D (6624) HTTP_CLIENT: http_on_body 106
D (6634) HTTP_CLIENT: HTTP_EVENT_ON_DATA, len=106
{
    "version": 0.1,
    "file": "https://chazestorage.blob.core.windows.net/firmware/app-template.bin"
}D (6644) HTTP_CLIENT: http_on_chunk_complete
D (6654) HTTP_CLIENT: content_length = -1
D (6654) HTTP_CLIENT: data_process=106, content_length=-1
D (6664) HTTP_CLIENT: http_on_chunk_complete
D (6664) HTTP_CLIENT: http_on_message_complete, parser=3ffb1350
D (6674) HTTP_CLIENT: HTTP_EVENT_ON_FINISH
I (6674) HTTP_CLIENT: HTTP chunk encoding Status = 200, content_length = -1
D (6684) HTTP_CLIENT: HTTP_EVENT_DISCONNECTED
D (6684) phy_init: wifi mac time delta: 95421
I (6694) HTTP_CLIENT: Finish http example

As you can see the content is printed (I printed it in the event handler), but in the function http_download_chunk() the returned content length is -1

Any help is appreciated.

SuperTechSaiyan3
Posts: 14
Joined: Tue Jan 01, 2019 6:59 pm

Re: HTTP Client: Content length -1, but receiving data

Postby SuperTechSaiyan3 » Fri Feb 01, 2019 5:57 pm

for what its worth I followed the esspressif docs website to send a post request to my website and I am having the same issue.

my website receives the data fine, but I still get content length=1. I tried to reverse engineer the problem to no avail so I decided to accept it I have had no issues so far and it seems to work.

jubueche
Posts: 32
Joined: Sat Jan 19, 2019 4:03 pm

Re: HTTP Client: Content length -1, but receiving data

Postby jubueche » Sun Feb 03, 2019 1:01 pm

I just set a flag in the event handler and saved the JSON to a global variable. Works pretty well, but maybe the example should be fixed?

SuperTechSaiyan3
Posts: 14
Joined: Tue Jan 01, 2019 6:59 pm

Re: HTTP Client: Content length -1, but receiving data

Postby SuperTechSaiyan3 » Mon Feb 04, 2019 5:33 am

yea I I thought I was doing something wrong on my end but if we are both having the same issue I'm thinking it's some sort of bug? I tried to trace the code to see why I was getting -1, but the code seem to be correct..

Who is online

Users browsing this forum: Majestic-12 [Bot] and 120 guests