Skip to content

Commit

Permalink
http_stream: make user_agent configurable
Browse files Browse the repository at this point in the history
Add a user_agent field to the http_stream and http_stream_cfg_t structs
so people can override the default user agent set by esp_http_client.

Also add it to the HTTP_STREAM_CFG_DEFAULT macro with value NULL, to
maintain current default behaviour.

Signed-off-by: Stijn Tintel <[email protected]>
  • Loading branch information
stintel committed Jun 27, 2023
1 parent b21df92 commit d25a287
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions components/audio_stream/http_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ typedef struct http_stream {
gzip_miniz_handle_t gzip; /* GZIP instance */
http_stream_hls_key_t *hls_key;
hls_handle_t *hls_media;
const char *user_agent;
} http_stream_t;

static esp_err_t http_stream_auto_connect_next_track(audio_element_handle_t el);
Expand Down Expand Up @@ -467,6 +468,7 @@ static esp_err_t _http_open(audio_element_handle_t self)
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0)) && defined CONFIG_MBEDTLS_CERTIFICATE_BUNDLE
.crt_bundle_attach = http->crt_bundle_attach,
#endif // (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0)) && defined CONFIG_MBEDTLS_CERTIFICATE_BUNDLE
.user_agent = http->user_agent,
};
http->client = esp_http_client_init(&http_cfg);
AUDIO_MEM_CHECK(TAG, http->client, return ESP_ERR_NO_MEM);
Expand Down Expand Up @@ -808,6 +810,7 @@ audio_element_handle_t http_stream_init(http_stream_cfg_t *config)
http->stream_type = config->type;
http->user_data = config->user_data;
http->cert_pem = config->cert_pem;
http->user_agent = config->user_agent;

if (config->crt_bundle_attach) {
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0))
Expand Down
2 changes: 2 additions & 0 deletions components/audio_stream/include/http_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ typedef struct {
const char *cert_pem; /*!< SSL server certification, PEM format as string, if the client requires to verify server */
esp_err_t (*crt_bundle_attach)(void *conf); /*!< Function pointer to esp_crt_bundle_attach. Enables the use of certification
bundle for server verification, must be enabled in menuconfig */
const char *user_agent;
} http_stream_cfg_t;


Expand All @@ -110,6 +111,7 @@ typedef struct {
.multi_out_num = 0, \
.cert_pem = NULL, \
.crt_bundle_attach = NULL, \
.user_agent = NULL, \
}

/**
Expand Down

0 comments on commit d25a287

Please sign in to comment.