0

I'm trying to download a firmware.bin file that is produced in a private GitHub repository. I have the code that is finding the right asset URL to download the file and per GitHub instructions the accept header needs to be set to accept: application/octet-stream in order to get the binary file.

I'm only getting JSON in response. If I run the same request through postman I'm getting a binary file as the body. I've tried downloading it using HTTPClient and I get the same JSON request. It seems the headers aren't being set as requested to tell GitHub to send the binary content as I'm just getting JSON

As for the ArduinoOTA abstraction, I can't see how to even try to set headers and in digging into the esp_https_ota functions and http_client functions there doesn't appear to be a way to set headers for any of these higher level abstractions because the http_config object has no place for headers as far as I can tell. I might file a feature request to allow for this, but am new to this programming area and want to check to see if I'm missing something first.

Code returns JSON, not binary. URL is GitHub rest API URL to the asset (works in postman)

HTTPClient http2;
http2.setAuthorization(githubname,githubpass);
http2.addHeader("Authorization","token MYTOKEN");    
http2.addHeader("accept","application/octet-stream");    
http2.begin( firmwareURL, GHAPI_CERT); //Specify the URL and certificate
double-beep
  • 5,031
  • 17
  • 33
  • 41

1 Answers1

1

With the ESP IDF HTTP client you can add headers to an initialized HTTP client using function esp_http_client_set_header().

esp_http_client_handle_t client = esp_http_client_init(&config);
esp_http_client_set_header(client, "HeaderKey", "HeaderValue");
err = esp_http_client_perform(client);

If using the HTTPS OTA API, you can register for a callback which gives you a handle to the underlying HTTP client. You can then do the exact same as in above example.

Tarmo
  • 3,728
  • 1
  • 8
  • 25
  • Thanks for pointing this out! In case anyone else comes across this post, I am using Platform IO with the arduino-esp32 framework which only packages v3.3 of the IDF unfortunately. I'll have to figure out how to get it to use the latest version of IDF to take advantage of that callback because it doesn't exist in 3.3. – Michael Bender Nov 04 '21 at 13:25