From 96d50ebd9334debcc47edf02ca3e8ca0fe913f20 Mon Sep 17 00:00:00 2001 From: Brandon Gillis Date: Fri, 1 Dec 2023 23:24:16 +0100 Subject: [PATCH] fix(#124): resolve all *.localhost to localhost --- .../bruno-electron/src/ipc/network/index.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/bruno-electron/src/ipc/network/index.js b/packages/bruno-electron/src/ipc/network/index.js index b11955823..8e0fbe21c 100644 --- a/packages/bruno-electron/src/ipc/network/index.js +++ b/packages/bruno-electron/src/ipc/network/index.js @@ -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'); @@ -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, @@ -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://github.com/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) {