Merge pull request #1070 from nelup20/feature/946-send_request_without_specifying_http

feat(#946): Send request even when protocol isn't specified in URL
This commit is contained in:
Anoop M D 2023-11-29 23:58:30 +05:30 committed by GitHub
commit 4e02f8ad45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View File

@ -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'
};

View File

@ -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');
});
});