mirror of
https://github.com/owntone/owntone-server.git
synced 2025-11-10 22:10:15 -05:00
[http/spotify] Add support for http sessions across multiple requests
This change allows to reuse curl handles for multiple requests. Reusing a curl handle improves performance if more than one request is made against a service (connection, session cache, dns cache are kept between requests).
This commit is contained in:
@@ -144,7 +144,7 @@ apple_rss_feedurl_get(const char *rss_url)
|
||||
ctx.url = url;
|
||||
ctx.input_body = evbuf;
|
||||
|
||||
ret = http_client_request(&ctx);
|
||||
ret = http_client_request(&ctx, NULL);
|
||||
if (ret < 0 || ctx.response_code != HTTP_OK)
|
||||
{
|
||||
evbuffer_free(evbuf);
|
||||
@@ -256,7 +256,7 @@ rss_xml_get(const char *url)
|
||||
CHECK_NULL(L_LIB, ctx.input_body = evbuffer_new());
|
||||
ctx.url = feedurl;
|
||||
|
||||
ret = http_client_request(&ctx);
|
||||
ret = http_client_request(&ctx, NULL);
|
||||
if (ret < 0 || ctx.response_code != HTTP_OK)
|
||||
{
|
||||
DPRINTF(E_LOG, L_LIB, "Failed to fetch RSS from '%s' (return %d, error code %d)\n", ctx.url, ret, ctx.response_code);
|
||||
|
||||
@@ -166,6 +166,7 @@ static const char *spotify_shows_uri = "https://api.spotify.com/v1/me/
|
||||
static const char *spotify_shows_episodes_uri = "https://api.spotify.com/v1/shows/%s/episodes";
|
||||
static const char *spotify_episode_uri = "https://api.spotify.com/v1/episodes/%s";
|
||||
|
||||
static struct http_client_session session = { 0 };
|
||||
|
||||
static enum spotify_item_type
|
||||
parse_type_from_uri(const char *uri)
|
||||
@@ -256,7 +257,7 @@ request_access_tokens(struct keyval *kv, const char **err)
|
||||
ctx.output_body = param;
|
||||
ctx.input_body = evbuffer_new();
|
||||
|
||||
ret = http_client_request(&ctx);
|
||||
ret = http_client_request(&ctx, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
*err = "Did not get a reply from Spotify";
|
||||
@@ -366,7 +367,7 @@ request_endpoint(const char *uri)
|
||||
|
||||
DPRINTF(E_DBG, L_SPOTIFY, "Request Spotify API endpoint: '%s')\n", uri);
|
||||
|
||||
ret = http_client_request(ctx);
|
||||
ret = http_client_request(ctx, &session);
|
||||
if (ret < 0)
|
||||
{
|
||||
DPRINTF(E_LOG, L_SPOTIFY, "Request for '%s' failed\n", uri);
|
||||
@@ -2321,10 +2322,15 @@ spotifywebapi_access_token_get(struct spotifywebapi_access_token *info)
|
||||
static int
|
||||
spotifywebapi_init()
|
||||
{
|
||||
CHECK_ERR(L_SPOTIFY, mutex_init(&token_lck));
|
||||
int ret;
|
||||
|
||||
// Required for libspotify backend
|
||||
return spotify_init();
|
||||
CHECK_ERR(L_SPOTIFY, mutex_init(&token_lck));
|
||||
ret = spotify_init();
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
http_client_session_init(&session);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -2333,6 +2339,7 @@ spotifywebapi_deinit()
|
||||
CHECK_ERR(L_SPOTIFY, pthread_mutex_destroy(&token_lck));
|
||||
|
||||
spotify_deinit();
|
||||
http_client_session_deinit(&session);
|
||||
|
||||
free_credentials();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user