mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-25 09:23:17 +01:00
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:
commit
4e02f8ad45
@ -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'
|
||||
};
|
||||
|
||||
|
@ -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');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user