mirror of
https://github.com/usebruno/bruno.git
synced 2025-06-20 11:48:03 +02:00
Merge pull request #951 from mirkogolze/bugfix/correct-proxy-settings-evaluation
#937, #921 improve evaluation of proxy configuration, allow empty port
This commit is contained in:
commit
11ce057310
@ -11,22 +11,20 @@ const ProxySettings = ({ proxyConfig, onUpdate }) => {
|
|||||||
protocol: Yup.string().oneOf(['http', 'https', 'socks4', 'socks5']),
|
protocol: Yup.string().oneOf(['http', 'https', 'socks4', 'socks5']),
|
||||||
hostname: Yup.string()
|
hostname: Yup.string()
|
||||||
.when('enabled', {
|
.when('enabled', {
|
||||||
is: true,
|
is: 'true',
|
||||||
then: (hostname) => hostname.required('Specify the hostname for your proxy.'),
|
then: (hostname) => hostname.required('Specify the hostname for your proxy.'),
|
||||||
otherwise: (hostname) => hostname.nullable()
|
otherwise: (hostname) => hostname.nullable()
|
||||||
})
|
})
|
||||||
.max(1024),
|
.max(1024),
|
||||||
port: Yup.number()
|
port: Yup.number()
|
||||||
.when('enabled', {
|
|
||||||
is: true,
|
|
||||||
then: (port) => port.required('Specify port between 1 and 65535').typeError('Specify port between 1 and 65535'),
|
|
||||||
otherwise: (port) => port.nullable().transform((_, val) => (val ? Number(val) : null))
|
|
||||||
})
|
|
||||||
.min(1)
|
.min(1)
|
||||||
.max(65535),
|
.max(65535)
|
||||||
|
.typeError('Specify port between 1 and 65535')
|
||||||
|
.nullable()
|
||||||
|
.transform((_, val) => (val ? Number(val) : null)),
|
||||||
auth: Yup.object()
|
auth: Yup.object()
|
||||||
.when('enabled', {
|
.when('enabled', {
|
||||||
is: true,
|
is: 'true',
|
||||||
then: Yup.object({
|
then: Yup.object({
|
||||||
enabled: Yup.boolean(),
|
enabled: Yup.boolean(),
|
||||||
username: Yup.string()
|
username: Yup.string()
|
||||||
|
@ -22,13 +22,11 @@ const ProxySettings = ({ close }) => {
|
|||||||
})
|
})
|
||||||
.max(1024),
|
.max(1024),
|
||||||
port: Yup.number()
|
port: Yup.number()
|
||||||
.when('enabled', {
|
|
||||||
is: true,
|
|
||||||
then: (port) => port.required('Specify port between 1 and 65535').typeError('Specify port between 1 and 65535'),
|
|
||||||
otherwise: (port) => port.nullable().transform((_, val) => (val ? Number(val) : null))
|
|
||||||
})
|
|
||||||
.min(1)
|
.min(1)
|
||||||
.max(65535),
|
.max(65535)
|
||||||
|
.typeError('Specify port between 1 and 65535')
|
||||||
|
.nullable()
|
||||||
|
.transform((_, val) => (val ? Number(val) : null)),
|
||||||
auth: Yup.object()
|
auth: Yup.object()
|
||||||
.when('enabled', {
|
.when('enabled', {
|
||||||
is: true,
|
is: true,
|
||||||
|
@ -3,7 +3,7 @@ const qs = require('qs');
|
|||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
const decomment = require('decomment');
|
const decomment = require('decomment');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { forOwn, each, extend, get, compact } = require('lodash');
|
const { forOwn, isUndefined, isNull, each, extend, get, compact } = require('lodash');
|
||||||
const FormData = require('form-data');
|
const FormData = require('form-data');
|
||||||
const prepareRequest = require('./prepare-request');
|
const prepareRequest = require('./prepare-request');
|
||||||
const interpolateVars = require('./interpolate-vars');
|
const interpolateVars = require('./interpolate-vars');
|
||||||
@ -136,14 +136,15 @@ const runSingleRequest = async function (
|
|||||||
const proxyAuthEnabled = get(brunoConfig, 'proxy.auth.enabled', false);
|
const proxyAuthEnabled = get(brunoConfig, 'proxy.auth.enabled', false);
|
||||||
const socksEnabled = proxyProtocol.includes('socks');
|
const socksEnabled = proxyProtocol.includes('socks');
|
||||||
|
|
||||||
|
let uriPort = isUndefined(proxyPort) || isNull(proxyPort) ? '' : `:${proxyPort}`;
|
||||||
let proxyUri;
|
let proxyUri;
|
||||||
if (proxyAuthEnabled) {
|
if (proxyAuthEnabled) {
|
||||||
const proxyAuthUsername = interpolateString(get(brunoConfig, 'proxy.auth.username'), interpolationOptions);
|
const proxyAuthUsername = interpolateString(get(brunoConfig, 'proxy.auth.username'), interpolationOptions);
|
||||||
const proxyAuthPassword = interpolateString(get(brunoConfig, 'proxy.auth.password'), interpolationOptions);
|
const proxyAuthPassword = interpolateString(get(brunoConfig, 'proxy.auth.password'), interpolationOptions);
|
||||||
|
|
||||||
proxyUri = `${proxyProtocol}://${proxyAuthUsername}:${proxyAuthPassword}@${proxyHostname}:${proxyPort}`;
|
proxyUri = `${proxyProtocol}://${proxyAuthUsername}:${proxyAuthPassword}@${proxyHostname}${uriPort}`;
|
||||||
} else {
|
} else {
|
||||||
proxyUri = `${proxyProtocol}://${proxyHostname}:${proxyPort}`;
|
proxyUri = `${proxyProtocol}://${proxyHostname}${uriPort}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (socksEnabled) {
|
if (socksEnabled) {
|
||||||
|
@ -6,11 +6,10 @@ const axios = require('axios');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const decomment = require('decomment');
|
const decomment = require('decomment');
|
||||||
const Mustache = require('mustache');
|
const Mustache = require('mustache');
|
||||||
const FormData = require('form-data');
|
|
||||||
const contentDispositionParser = require('content-disposition');
|
const contentDispositionParser = require('content-disposition');
|
||||||
const mime = require('mime-types');
|
const mime = require('mime-types');
|
||||||
const { ipcMain } = require('electron');
|
const { ipcMain } = require('electron');
|
||||||
const { forOwn, extend, each, get, compact } = require('lodash');
|
const { isUndefined, isNull, each, get, compact } = require('lodash');
|
||||||
const { VarsRuntime, AssertRuntime, ScriptRuntime, TestRuntime } = require('@usebruno/js');
|
const { VarsRuntime, AssertRuntime, ScriptRuntime, TestRuntime } = require('@usebruno/js');
|
||||||
const prepareRequest = require('./prepare-request');
|
const prepareRequest = require('./prepare-request');
|
||||||
const prepareGqlIntrospectionRequest = require('./prepare-gql-introspection-request');
|
const prepareGqlIntrospectionRequest = require('./prepare-gql-introspection-request');
|
||||||
@ -72,22 +71,6 @@ const getEnvVars = (environment = {}) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const getSize = (data) => {
|
|
||||||
if (!data) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof data === 'string') {
|
|
||||||
return Buffer.byteLength(data, 'utf8');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof data === 'object') {
|
|
||||||
return Buffer.byteLength(safeStringifyJSON(data), 'utf8');
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
const configureRequest = async (
|
const configureRequest = async (
|
||||||
collectionUid,
|
collectionUid,
|
||||||
request,
|
request,
|
||||||
@ -143,7 +126,7 @@ const configureRequest = async (
|
|||||||
|
|
||||||
// proxy configuration
|
// proxy configuration
|
||||||
let proxyConfig = get(brunoConfig, 'proxy', {});
|
let proxyConfig = get(brunoConfig, 'proxy', {});
|
||||||
let proxyEnabled = get(proxyConfig, 'enabled', false);
|
let proxyEnabled = get(proxyConfig, 'enabled', 'global');
|
||||||
if (proxyEnabled === 'global') {
|
if (proxyEnabled === 'global') {
|
||||||
proxyConfig = preferencesUtil.getGlobalProxyConfig();
|
proxyConfig = preferencesUtil.getGlobalProxyConfig();
|
||||||
proxyEnabled = get(proxyConfig, 'enabled', false);
|
proxyEnabled = get(proxyConfig, 'enabled', false);
|
||||||
@ -156,14 +139,15 @@ const configureRequest = async (
|
|||||||
const proxyAuthEnabled = get(proxyConfig, 'auth.enabled', false);
|
const proxyAuthEnabled = get(proxyConfig, 'auth.enabled', false);
|
||||||
const socksEnabled = proxyProtocol.includes('socks');
|
const socksEnabled = proxyProtocol.includes('socks');
|
||||||
|
|
||||||
|
let uriPort = isUndefined(proxyPort) || isNull(proxyPort) ? '' : `:${proxyPort}`;
|
||||||
let proxyUri;
|
let proxyUri;
|
||||||
if (proxyAuthEnabled) {
|
if (proxyAuthEnabled) {
|
||||||
const proxyAuthUsername = interpolateString(get(proxyConfig, 'auth.username'), interpolationOptions);
|
const proxyAuthUsername = interpolateString(get(proxyConfig, 'auth.username'), interpolationOptions);
|
||||||
const proxyAuthPassword = interpolateString(get(proxyConfig, 'auth.password'), interpolationOptions);
|
const proxyAuthPassword = interpolateString(get(proxyConfig, 'auth.password'), interpolationOptions);
|
||||||
|
|
||||||
proxyUri = `${proxyProtocol}://${proxyAuthUsername}:${proxyAuthPassword}@${proxyHostname}:${proxyPort}`;
|
proxyUri = `${proxyProtocol}://${proxyAuthUsername}:${proxyAuthPassword}@${proxyHostname}${uriPort}`;
|
||||||
} else {
|
} else {
|
||||||
proxyUri = `${proxyProtocol}://${proxyHostname}:${proxyPort}`;
|
proxyUri = `${proxyProtocol}://${proxyHostname}${uriPort}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (socksEnabled) {
|
if (socksEnabled) {
|
||||||
@ -203,10 +187,10 @@ const configureRequest = async (
|
|||||||
const parseDataFromResponse = (response) => {
|
const parseDataFromResponse = (response) => {
|
||||||
const dataBuffer = Buffer.from(response.data);
|
const dataBuffer = Buffer.from(response.data);
|
||||||
// Parse the charset from content type: https://stackoverflow.com/a/33192813
|
// Parse the charset from content type: https://stackoverflow.com/a/33192813
|
||||||
const charset = /charset=([^()<>@,;:\"/[\]?.=\s]*)/i.exec(response.headers['Content-Type'] || '');
|
const charset = /charset=([^()<>@,;:"/[\]?.=\s]*)/i.exec(response.headers['Content-Type'] || '');
|
||||||
// Overwrite the original data for backwards compatability
|
// Overwrite the original data for backwards compatability
|
||||||
let data = dataBuffer.toString(charset || 'utf-8');
|
let data = dataBuffer.toString(charset || 'utf-8');
|
||||||
// Try to parse response to JSON, this can quitly fail
|
// Try to parse response to JSON, this can quietly fail
|
||||||
try {
|
try {
|
||||||
data = JSON.parse(response.data);
|
data = JSON.parse(response.data);
|
||||||
} catch {}
|
} catch {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user