Third DNS fallback

This commit is contained in:
Gregory Schier 2016-12-23 11:31:38 -08:00
parent 22a3f65bbe
commit 18d11ff117
5 changed files with 77 additions and 20 deletions

View File

@ -13,6 +13,13 @@ import {getRenderedRequest} from './render';
import * as fs from 'fs';
import * as db from './database';
// Defined fallback strategies for DNS lookup
const FAMILY_FALLBACKS = [
6, // IPv6
4, // IPv4
null // If those don't work, don't specify and let request do it's thing
];
let cancelRequestFunction = null;
export function cancelCurrentRequest () {
@ -105,7 +112,7 @@ export function _buildRequestConfig (renderedRequest, patch = {}) {
return Object.assign(config, patch);
}
export function _actuallySend (renderedRequest, workspace, settings, forceIPv4 = false) {
export function _actuallySend (renderedRequest, workspace, settings, familyIndex = 0) {
return new Promise(async (resolve, reject) => {
async function handleError (err, prefix = '') {
await models.response.create({
@ -176,7 +183,10 @@ export function _actuallySend (renderedRequest, workspace, settings, forceIPv4 =
// Set the IP family. This fallback behaviour is copied from Curl
try {
config.family = forceIPv4 ? 4 : 6;
const family = FAMILY_FALLBACKS[familyIndex];
if (family) {
config.family = family;
}
} catch (err) {
return handleError(err, 'Failed to set IP family');
}
@ -187,6 +197,7 @@ export function _actuallySend (renderedRequest, workspace, settings, forceIPv4 =
// Failed to connect while prioritizing IPv6 address, fallback to IPv4
const isNetworkRelatedError = (
err.code === 'ENOENT' || // No entry
err.code === 'ENODATA' || // DNS resolve failed
err.code === 'ENOTFOUND' || // Could not resolve DNS
err.code === 'ECONNREFUSED' || // Could not talk to server
@ -194,9 +205,12 @@ export function _actuallySend (renderedRequest, workspace, settings, forceIPv4 =
err.code === 'ENETUNREACH' // Could not access the network
);
if (!forceIPv4 && isNetworkRelatedError) {
console.log('-- Falling back to IPv4 --');
_actuallySend(renderedRequest, workspace, settings, true).then(resolve, reject);
const nextFamilyIndex = familyIndex + 1;
if (isNetworkRelatedError && nextFamilyIndex < FAMILY_FALLBACKS.length) {
const family = FAMILY_FALLBACKS[nextFamilyIndex];
console.log(`-- Falling back to family ${family} --`);
_actuallySend(renderedRequest, workspace, settings, nextFamilyIndex)
.then(resolve, reject);
return;
}

View File

@ -1,7 +1,7 @@
{
"private": true,
"name": "insomnia",
"version": "4.0.9",
"version": "4.0.12",
"productName": "Insomnia",
"longName": "Insomnia REST Client",
"description": "A simple and beautiful REST API client",
@ -12,7 +12,6 @@
"analytics-node": "^2.1.0",
"classnames": "^2.2.3",
"electron-context-menu": "^0.4.0",
"electron-cookies": "^1.1.0",
"electron-squirrel-startup": "^1.0.0",
"hkdf": "0.0.2",
"httpsnippet": "git@github.com:getinsomnia/httpsnippet.git#a3a2c0a0167fa844bf92df52a1442fa1d68a9053",

View File

@ -64,6 +64,7 @@ class Dropdown extends Component {
hide () {
this.setState({open: false});
this.props.onHide && this.props.onHide();
}
show () {
@ -72,6 +73,7 @@ class Dropdown extends Component {
const dropUp = dropdownTop > bodyHeight - 200;
this.setState({open: true, dropUp});
this.props.onOpen && this.props.onOpen();
}
toggle () {
@ -156,7 +158,9 @@ class Dropdown extends Component {
Dropdown.propTypes = {
right: PropTypes.bool,
outline: PropTypes.bool,
wide: PropTypes.bool
wide: PropTypes.bool,
onOpen: PropTypes.func,
onHide: PropTypes.func,
};
export default Dropdown;

View File

@ -11,8 +11,25 @@ import {trackEvent} from '../../../analytics/index';
import Link from '../base/Link';
import WorkspaceSettingsModal from '../modals/WorkspaceSettingsModal';
import WorkspaceShareSettingsModal from '../modals/WorkspaceShareSettingsModal';
import * as session from '../../../sync/session';
import PromptButton from '../base/PromptButton';
import LoginModal from '../modals/LoginModal';
class WorkspaceDropdown extends Component {
state = {
loggedIn: false
};
_handleDropdownOpen = () => {
if (this.state.loggedIn !== session.isLoggedIn()) {
this.setState({loggedIn: session.isLoggedIn()});
}
};
_handleShowLogin = () => {
showModal(LoginModal);
};
_handleShowExport = () => showModal(SettingsModal, TAB_INDEX_EXPORT);
_handleShowSettings = () => showModal(SettingsModal);
_handleShowWorkspaceSettings = () => {
@ -20,11 +37,11 @@ class WorkspaceDropdown extends Component {
workspace: this.props.activeWorkspace,
});
};
_handleShowShareSettings = () => {
showModal(WorkspaceShareSettingsModal, {
workspace: this.props.activeWorkspace,
});
};
// _handleShowShareSettings = () => {
// showModal(WorkspaceShareSettingsModal, {
// workspace: this.props.activeWorkspace,
// });
// };
_handleSwitchWorkspace = workspaceId => {
this.props.handleSetActiveWorkspace(workspaceId);
@ -58,8 +75,9 @@ class WorkspaceDropdown extends Component {
const nonActiveWorkspaces = workspaces.filter(w => w._id !== activeWorkspace._id);
const classes = classnames(className, 'wide', 'workspace-dropdown');
return (
<Dropdown className={classnames(className, 'wide', 'workspace-dropdown')} {...other}>
<Dropdown className={classes} onOpen={this._handleDropdownOpen} {...other}>
<DropdownButton className="btn wide">
<h1 className="no-pad text-left">
<div className="pull-right">
@ -76,7 +94,7 @@ class WorkspaceDropdown extends Component {
<DropdownHint char="&#8679;,"/>
</DropdownItem>
{/*<DropdownItem onClick={this._handleShowShareSettings}>*/}
{/*<i className="fa fa-user"/> Share <strong>{activeWorkspace.name}</strong>*/}
{/*<i className="fa fa-user"/> Share <strong>{activeWorkspace.name}</strong>*/}
{/*</DropdownItem>*/}
<DropdownDivider>Switch Workspace</DropdownDivider>
@ -99,9 +117,32 @@ class WorkspaceDropdown extends Component {
<DropdownItem onClick={this._handleShowExport}>
<i className="fa fa-share"/> Import/Export
</DropdownItem>
<DropdownItem buttonClass={Link} href="https://insomnia.rest/teams/" button={true}>
<i className="fa fa-users"/> Invite Your Team
</DropdownItem>
{!this.state.loggedIn ? [
<DropdownItem key="login"
onClick={this._handleShowLogin}
addIcon={true}>
<i className="fa fa-sign-in"/> Log In
</DropdownItem>,
<DropdownItem key="invite"
buttonClass={Link}
href="https://insomnia.rest/pricing/"
button={true}>
<i className="fa fa-users"/> Upgrade to Plus
</DropdownItem>,
] : [
<DropdownItem key="manage"
buttonClass={Link}
href="https://insomnia.rest/app/"
button={true}>
<i className="fa fa-user"/> Manage Account
</DropdownItem>,
<DropdownItem key="logout"
buttonClass={PromptButton}
onClick={session.logout}
addIcon={true}>
<i className="fa fa-sign-out"/> Log Out
</DropdownItem>,
]}
</Dropdown>
)
}

View File

@ -97,7 +97,6 @@
"classnames": "^2.2.3",
"codemirror": "^5.22.0",
"electron-context-menu": "^0.4.0",
"electron-cookies": "^1.1.0",
"electron-squirrel-startup": "^1.0.0",
"hkdf": "0.0.2",
"httpsnippet": "git@github.com:getinsomnia/httpsnippet.git#a3a2c0a0167fa844bf92df52a1442fa1d68a9053",
@ -148,7 +147,7 @@
"concurrently": "^2.0.0",
"cross-env": "^2.0.0",
"css-loader": "^0.23.1",
"electron": "^1.4.10",
"electron": "^1.4.13",
"electron-builder": "^10.5.0",
"express": "^4.14.0",
"file-loader": "^0.9.0",