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 Sep 27, 2023
1 parent aea0890 commit 76e4a5d
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 @@ -100,6 +100,7 @@ typedef struct http_stream {
int request_range_size;
int64_t request_range_end;
bool is_last_range;
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 @@ -586,6 +587,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 @@ -870,6 +872,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 @@ -94,6 +94,7 @@ typedef struct {
int request_range_size; /*!< Range size setting for header `Range: bytes=start-end`
Request full range of resource if set to 0
Range size bigger than request size is recommended */
const char *user_agent; /*!< The User Agent string to send with HTTP requests */
} http_stream_cfg_t;

#define HTTP_STREAM_TASK_STACK (6 * 1024)
Expand All @@ -115,6 +116,7 @@ typedef struct {
.multi_out_num = 0, \
.cert_pem = NULL, \
.crt_bundle_attach = NULL, \
.user_agent = NULL, \
}

/**
Expand Down

0 comments on commit 76e4a5d

Please sign in to comment.