diff --git a/packages/bruno-electron/src/ipc/network/prepare-request.js b/packages/bruno-electron/src/ipc/network/prepare-request.js index bd5f7a8d..c5ec9564 100644 --- a/packages/bruno-electron/src/ipc/network/prepare-request.js +++ b/packages/bruno-electron/src/ipc/network/prepare-request.js @@ -70,9 +70,16 @@ const setAuthHeaders = (axiosRequest, request, collectionRoot) => { return axiosRequest; }; +const protocolRegex = /([a-zA-Z]{2,20}:\/\/)(.*)/; + const prepareRequest = (request, collectionRoot) => { const headers = {}; let contentTypeDefined = false; + let url = request.url; + + if (!protocolRegex.test(url)) { + url = `http://${url}`; + } // collection headers each(get(collectionRoot, 'request.headers', []), (h) => { @@ -95,8 +102,8 @@ const prepareRequest = (request, collectionRoot) => { let axiosRequest = { method: request.method, - url: request.url, - headers: headers, + url, + headers, responseType: 'arraybuffer' }; diff --git a/packages/bruno-electron/tests/network/prepare-request.spec.js b/packages/bruno-electron/tests/network/prepare-request.spec.js new file mode 100644 index 00000000..5c97f23a --- /dev/null +++ b/packages/bruno-electron/tests/network/prepare-request.spec.js @@ -0,0 +1,13 @@ +const prepareRequest = require('../../src/ipc/network/prepare-request'); + +describe('prepare-request: prepareRequest', () => { + it("Should add 'http://' to the URL if no protocol is specified", () => { + 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'); + }); +});