From cfe245456d46539a4d6022ad67b8607123f68399 Mon Sep 17 00:00:00 2001 From: Phil Tsaryk Date: Mon, 2 Sep 2024 21:14:32 +0200 Subject: [PATCH] feat: add support for default request headers --- src/spotify-web-api.js | 12 ++++++++---- src/webapi-request.js | 7 +++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/spotify-web-api.js b/src/spotify-web-api.js index 2a756da8..668818af 100644 --- a/src/spotify-web-api.js +++ b/src/spotify-web-api.js @@ -21,6 +21,10 @@ SpotifyWebApi.prototype = { return this._credentials; }, + setDefaultHeaders: function(defaultHeaders) { + WebApiRequest.setDefaultHeaders(defaultHeaders); + }, + resetCredentials: function() { this._credentials = null; }, @@ -593,7 +597,7 @@ SpotifyWebApi.prototype = { .withBodyParameters( { tracks: tracks - }, + }, options ) .build() @@ -971,7 +975,7 @@ SpotifyWebApi.prototype = { }, - /** + /** * Get the Current User's Available Devices * @param {requestCallback} [callback] Optional callback method to be called instead of the promise. * @returns {Promise|undefined} A promise that if successful, resolves into an array of device objects, @@ -1016,7 +1020,7 @@ SpotifyWebApi.prototype = { /** * Transfer a User's Playback - * @param {string[]} [deviceIds] An _array_ containing a device ID on which playback should be started/transferred. + * @param {string[]} [deviceIds] An _array_ containing a device ID on which playback should be started/transferred. * (NOTE: The API is currently only supporting a single device ID.) * @param {Object} [options] Options, the only one being 'play'. * @param {requestCallback} [callback] Optional callback method to be called instead of the promise. @@ -1175,7 +1179,7 @@ SpotifyWebApi.prototype = { /** * Set Shuffle Mode On The Current User's Playback - * @param {boolean} [state] State + * @param {boolean} [state] State * @param {Object} [options] Options, being device_id. If left empty will target the user's currently active device. * @param {requestCallback} [callback] Optional callback method to be called instead of the promise. * @example setShuffle({state: 'false'}).then(...) diff --git a/src/webapi-request.js b/src/webapi-request.js index 79e9dc2a..254d6a7c 100644 --- a/src/webapi-request.js +++ b/src/webapi-request.js @@ -6,10 +6,17 @@ var DEFAULT_HOST = 'api.spotify.com', DEFAULT_PORT = 443, DEFAULT_SCHEME = 'https'; +let defaultHeaders = null; + module.exports.builder = function(accessToken) { return Request.builder() .withHost(DEFAULT_HOST) .withPort(DEFAULT_PORT) .withScheme(DEFAULT_SCHEME) + .withHeaders(defaultHeaders) .withAuth(accessToken); }; + +module.exports.setDefaultHeaders = function(headers) { + defaultHeaders = headers; +}