forked from axios/axios
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not modify config.url when using a relative baseURL (resolves axio…
…s#1628) (axios#2391) * Adding tests to show config.url mutation Because config.url is modified while processing the request when the baseURL is set, it is impossible to perform a retry with the provided config object. Ref axios#1628 * Fixing url combining without modifying config.url As config.url is not modified anymore during the request processing. The request can safely be retried after it failed with the provided config. resolves axios#1628
- Loading branch information
1 parent
98e4acd
commit 6fe506f
Showing
7 changed files
with
85 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
var isAbsoluteURL = require('../helpers/isAbsoluteURL'); | ||
var combineURLs = require('../helpers/combineURLs'); | ||
|
||
/** | ||
* Creates a new URL by combining the baseURL with the requestedURL, | ||
* only when the requestedURL is not already an absolute URL. | ||
* If the requestURL is absolute, this function returns the requestedURL untouched. | ||
* | ||
* @param {string} baseURL The base URL | ||
* @param {string} requestedURL Absolute or relative URL to combine | ||
* @returns {string} The combined full path | ||
*/ | ||
module.exports = function buildFullPath(baseURL, requestedURL) { | ||
if (baseURL && !isAbsoluteURL(requestedURL)) { | ||
return combineURLs(baseURL, requestedURL); | ||
} | ||
return requestedURL; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var buildFullPath = require('../../../lib/core/buildFullPath'); | ||
|
||
describe('helpers::buildFullPath', function () { | ||
it('should combine URLs when the requestedURL is relative', function () { | ||
expect(buildFullPath('https://api.github.com', '/users')).toBe('https://api.github.com/users'); | ||
}); | ||
|
||
it('should return the requestedURL when it is absolute', function () { | ||
expect(buildFullPath('https://api.github.com', 'https://api.example.com/users')).toBe('https://api.example.com/users'); | ||
}); | ||
|
||
it('should not combine URLs when the baseURL is not configured', function () { | ||
expect(buildFullPath(undefined, '/users')).toBe('/users'); | ||
}); | ||
|
||
it('should combine URLs when the baseURL and requestedURL are relative', function () { | ||
expect(buildFullPath('/api', '/users')).toBe('/api/users'); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters