mirror of
https://github.com/usebruno/bruno.git
synced 2025-01-03 12:39:34 +01:00
feat(#946): Use Regex to check if URL has protocol
This commit is contained in:
parent
2b08468581
commit
ce545724bd
@ -70,14 +70,14 @@ const setAuthHeaders = (axiosRequest, request, collectionRoot) => {
|
||||
return axiosRequest;
|
||||
};
|
||||
|
||||
const PROTOCOLS = ['http://', 'https://', 'wss://'];
|
||||
const protocolRegex = /([a-zA-Z]{2,20}:\/\/)(.*)/;
|
||||
|
||||
const prepareRequest = (request, collectionRoot) => {
|
||||
const headers = {};
|
||||
let contentTypeDefined = false;
|
||||
let url = request.url;
|
||||
|
||||
if (PROTOCOLS.find((protocol) => url.startsWith(protocol)) === undefined) {
|
||||
if (!protocolRegex.test(url)) {
|
||||
url = `http://${url}`;
|
||||
}
|
||||
|
||||
@ -102,8 +102,8 @@ const prepareRequest = (request, collectionRoot) => {
|
||||
|
||||
let axiosRequest = {
|
||||
method: request.method,
|
||||
url: url,
|
||||
headers: headers,
|
||||
url,
|
||||
headers,
|
||||
responseType: 'arraybuffer'
|
||||
};
|
||||
|
||||
|
@ -5,4 +5,9 @@ describe('prepare-request: prepareRequest', () => {
|
||||
const request = prepareRequest({ method: 'GET', url: 'test', body: {} });
|
||||
expect(request.url).toEqual('http://test');
|
||||
});
|
||||
|
||||
it("Should NOT add 'http://' to the URL if a protocol is specified", () => {
|
||||
const request = prepareRequest({ method: 'GET', url: 'ftp://test', body: {} });
|
||||
expect(request.url).toEqual('ftp://test');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user