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) {