Skip to content

Commit

Permalink
fix(#124): resolve all *.localhost to localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonGillis committed Dec 1, 2023
1 parent 6632ae1 commit 96d50eb
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/bruno-electron/src/ipc/network/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const os = require('os');
const fs = require('fs');
const qs = require('qs');
const parseUrl = require('url').parse;
const https = require('https');
const axios = require('axios');
const path = require('path');
Expand Down Expand Up @@ -74,6 +75,14 @@ const getEnvVars = (environment = {}) => {

const protocolRegex = /([a-zA-Z]{2,20}:\/\/)(.*)/;

const getTld = (hostname) => {
if (!hostname) {
return '';
}

return hostname.substring(hostname.lastIndexOf('.') + 1);
};

const configureRequest = async (
collectionUid,
request,
Expand Down Expand Up @@ -174,6 +183,15 @@ const configureRequest = async (
});
}

// resolve all *.localhost to localhost
// RFC: 6761 section 6.3 (https://tools.ietf.org/html/rfc6761#section-6.3)
// @see https:/usebruno/bruno/issues/124
let parsedUrl = parseUrl(request.url);
if (getTld(parsedUrl.hostname) === 'localhost') {
request.headers['Host'] = parsedUrl.hostname;
request.url = request.url.replace(parsedUrl.hostname, 'localhost');
}

const axiosInstance = makeAxiosInstance();

if (request.awsv4config) {
Expand Down

0 comments on commit 96d50eb

Please sign in to comment.