mirror of
https://github.com/Kong/insomnia
synced 2024-11-07 22:30:15 +00:00
Fix some minor bugs (#139)
* Keyboard shortcut for hotkeys * Fixed some small bugs
This commit is contained in:
parent
2aabe29289
commit
f145b968be
@ -27,6 +27,14 @@ export function filterHeaders (headers, name) {
|
||||
});
|
||||
}
|
||||
|
||||
export function hasContentTypeHeader (headers) {
|
||||
return filterHeaders(headers, 'content-type').length > 0;
|
||||
}
|
||||
|
||||
export function hasContentLengthHeader (headers) {
|
||||
return filterHeaders(headers, 'content-length').length > 0;
|
||||
}
|
||||
|
||||
export function hasAuthHeader (headers) {
|
||||
return filterHeaders(headers, 'authorization').length > 0;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import * as db from './database';
|
||||
import * as templating from '../templating';
|
||||
|
||||
export function render (obj, context = {}) {
|
||||
return recursiveRender(obj, context, true);
|
||||
return recursiveRender(obj, context);
|
||||
}
|
||||
|
||||
export async function buildRenderContext (ancestors, rootEnvironment, subEnvironment) {
|
||||
@ -83,7 +83,6 @@ export async function recursiveRender (originalObj, context = {}, blacklistPathR
|
||||
try {
|
||||
x = await templating.render(x, {context, path});
|
||||
} catch (err) {
|
||||
// TODO: Show paths here in errors
|
||||
throw err;
|
||||
}
|
||||
} else if (Array.isArray(x)) {
|
||||
@ -170,7 +169,14 @@ export async function getRenderedRequest (request, environmentId) {
|
||||
}
|
||||
|
||||
async function _objectDeepAssignRender (base, obj) {
|
||||
for (const key of Object.keys(obj)) {
|
||||
// Sort the keys that may have Nunjucks last, so that other keys get
|
||||
// defined first. Very important if env variables defined in same obj
|
||||
// (eg. {"foo": "{{ bar }}", "bar": "Hello World!"})
|
||||
const keys = Object.keys(obj).sort((k1, k2) =>
|
||||
obj[k1].match && obj[k1].match(/({{)/) ? 1 : -1
|
||||
);
|
||||
|
||||
for (const key of keys) {
|
||||
/*
|
||||
* If we're overwriting a string, try to render it first with the base as
|
||||
* a context. This allows for the following scenario:
|
||||
|
@ -55,6 +55,10 @@ export function newAuth (type, oldAuth = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
export function newBodyNone () {
|
||||
return {};
|
||||
}
|
||||
|
||||
export function newBodyRaw (rawBody, contentType) {
|
||||
if (typeof contentType !== 'string') {
|
||||
return {text: rawBody};
|
||||
@ -173,7 +177,7 @@ export function updateMimeType (request, mimeType, doCreate = false) {
|
||||
body = newBodyFile('');
|
||||
} else if (typeof mimeType !== 'string') {
|
||||
// No body
|
||||
body = newBodyRaw('');
|
||||
body = newBodyNone();
|
||||
} else {
|
||||
// Raw Content-Type (ex: application/json)
|
||||
body = request.body.params
|
||||
|
@ -8,7 +8,7 @@ import * as models from '../models';
|
||||
import * as querystring from '../common/querystring';
|
||||
import * as util from '../common/misc.js';
|
||||
import {AUTH_BASIC, AUTH_DIGEST, AUTH_NTLM, CONTENT_TYPE_FORM_DATA, CONTENT_TYPE_FORM_URLENCODED, DEBOUNCE_MILLIS, getAppVersion} from '../common/constants';
|
||||
import {describeByteSize, hasAcceptHeader, hasAuthHeader, hasUserAgentHeader, setDefaultProtocol} from '../common/misc';
|
||||
import {describeByteSize, hasAcceptHeader, hasAuthHeader, hasContentTypeHeader, hasUserAgentHeader, setDefaultProtocol} from '../common/misc';
|
||||
import {getRenderedRequest} from '../common/render';
|
||||
import fs from 'fs';
|
||||
import * as db from '../common/database';
|
||||
@ -313,7 +313,7 @@ export function _actuallySend (renderedRequest, workspace, settings) {
|
||||
const fn = () => fs.closeSync(fd);
|
||||
curl.on('end', fn);
|
||||
curl.on('error', fn);
|
||||
} else if (typeof renderedRequest.body.text === 'string') {
|
||||
} else if (renderedRequest.body.text) {
|
||||
setOpt(Curl.option.POSTFIELDS, renderedRequest.body.text);
|
||||
} else {
|
||||
// No body
|
||||
@ -335,7 +335,7 @@ export function _actuallySend (renderedRequest, workspace, settings) {
|
||||
});
|
||||
|
||||
// Handle Authorization header
|
||||
if (!hasAuthHeader(renderedRequest.headers) && !renderedRequest.authentication.disabled) {
|
||||
if (!hasAuthHeader(headers) && !renderedRequest.authentication.disabled) {
|
||||
if (renderedRequest.authentication.type === AUTH_BASIC) {
|
||||
const {username, password} = renderedRequest.authentication;
|
||||
setOpt(Curl.option.HTTPAUTH, Curl.auth.BASIC);
|
||||
@ -363,22 +363,27 @@ export function _actuallySend (renderedRequest, workspace, settings) {
|
||||
}
|
||||
}
|
||||
|
||||
// Set User-Agent if it't not already in headers
|
||||
if (!hasUserAgentHeader(headers)) {
|
||||
setOpt(Curl.option.USERAGENT, `insomnia/${getAppVersion()}`);
|
||||
}
|
||||
|
||||
// Set Accept encoding
|
||||
if (!hasAcceptHeader(headers)) {
|
||||
setOpt(Curl.option.ENCODING, ''); // Accept anything
|
||||
}
|
||||
|
||||
// Prevent curl from adding default content-type header
|
||||
if (!hasContentTypeHeader(headers)) {
|
||||
headers.push({name: 'content-type', value: ''});
|
||||
}
|
||||
|
||||
// NOTE: This is last because headers might be modified multiple times
|
||||
const headerStrings = headers
|
||||
.filter(h => h.name)
|
||||
.map(h => `${(h.name || '').trim()}: ${h.value}`);
|
||||
setOpt(Curl.option.HTTPHEADER, headerStrings);
|
||||
|
||||
// Set User-Agent if it't not already in headers
|
||||
if (!hasUserAgentHeader(renderedRequest.headers)) {
|
||||
setOpt(Curl.option.USERAGENT, `insomnia/${getAppVersion()}`);
|
||||
}
|
||||
|
||||
// Set Accept encoding
|
||||
if (!hasAcceptHeader(renderedRequest.headers)) {
|
||||
setOpt(Curl.option.ENCODING, ''); // Accept anything
|
||||
}
|
||||
|
||||
// Handle the response ending
|
||||
curl.on('end', function (_1, _2, curlHeaders) {
|
||||
// Headers are an array (one for each redirect)
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "insomnia",
|
||||
"version": "5.0.3",
|
||||
"version": "5.0.4",
|
||||
"productName": "Insomnia",
|
||||
"longName": "Insomnia REST Client",
|
||||
"description": "Debug APIs like a human, not a robot",
|
||||
|
@ -32,7 +32,7 @@ CodeMirror.defineExtension('enableNunjucksTags', function (handleRender) {
|
||||
|
||||
async function _highlightNunjucksTags (render) {
|
||||
const renderCacheKey = Math.random() + '';
|
||||
const renderString = text => render(text, true, renderCacheKey);
|
||||
const renderString = text => render(text, renderCacheKey);
|
||||
|
||||
const activeMarks = [];
|
||||
const doc = this.getDoc();
|
||||
@ -237,7 +237,7 @@ async function _updateElementText (render, mark, text) {
|
||||
}
|
||||
} else {
|
||||
// Render if it's a variable
|
||||
el.innerHTML = `<label>var</label> ${cleanedStr}`.trim();
|
||||
el.innerHTML = `<label></label>${cleanedStr}`.trim();
|
||||
el.title = await render(str);
|
||||
}
|
||||
el.setAttribute('data-error', 'off');
|
||||
|
@ -10,6 +10,7 @@ import ModalHeader from '../base/modal-header';
|
||||
import ModalFooter from '../base/modal-footer';
|
||||
import {exportHar} from '../../../common/har';
|
||||
import {trackEvent} from '../../../analytics/index';
|
||||
import Link from '../base/link';
|
||||
|
||||
const DEFAULT_TARGET = availableTargets().find(t => t.key === 'shell');
|
||||
const DEFAULT_CLIENT = DEFAULT_TARGET.clients.find(t => t.key === 'curl');
|
||||
@ -164,6 +165,12 @@ class GenerateCodeModal extends PureComponent {
|
||||
/>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<div className="margin-left italic txt-sm tall">
|
||||
* Code snippets generated by
|
||||
<Link href="https://github.com/Mashape/httpsnippet">
|
||||
httpsnippet
|
||||
</Link>
|
||||
</div>
|
||||
<button className="btn" onClick={this.hide}>
|
||||
Done
|
||||
</button>
|
||||
|
@ -210,7 +210,7 @@ class RequestSwitcherModal extends PureComponent {
|
||||
const requestGroups = workspaceChildren.filter(d => d.type === models.requestGroup.type);
|
||||
|
||||
return (
|
||||
<Modal ref={this._setModalRef} dontFocus>
|
||||
<Modal ref={this._setModalRef} dontFocus tall>
|
||||
<ModalHeader hideCloseButton>
|
||||
<div className="pull-right txt-md pad-right">
|
||||
<span className="monospace">tab</span> or
|
||||
|
@ -23,8 +23,7 @@ class WorkspaceEnvironmentsEditModal extends PureComponent {
|
||||
isValid: true,
|
||||
subEnvironments: [],
|
||||
rootEnvironment: null,
|
||||
activeEnvironmentId: null,
|
||||
forceRefreshKey: 0
|
||||
activeEnvironmentId: null
|
||||
};
|
||||
}
|
||||
|
||||
@ -72,8 +71,7 @@ class WorkspaceEnvironmentsEditModal extends PureComponent {
|
||||
workspace,
|
||||
rootEnvironment,
|
||||
subEnvironments,
|
||||
activeEnvironmentId,
|
||||
forceRefreshKey: Date.now()
|
||||
activeEnvironmentId
|
||||
});
|
||||
}
|
||||
|
||||
@ -176,8 +174,7 @@ class WorkspaceEnvironmentsEditModal extends PureComponent {
|
||||
const {
|
||||
subEnvironments,
|
||||
rootEnvironment,
|
||||
isValid,
|
||||
forceRefreshKey
|
||||
isValid
|
||||
} = this.state;
|
||||
|
||||
const activeEnvironment = this._getActiveEnvironment();
|
||||
@ -260,7 +257,7 @@ class WorkspaceEnvironmentsEditModal extends PureComponent {
|
||||
editorKeyMap={editorKeyMap}
|
||||
lineWrapping={lineWrapping}
|
||||
ref={this._setEditorRef}
|
||||
key={`${forceRefreshKey}::${(activeEnvironment ? activeEnvironment._id : 'n/a')}`}
|
||||
key={activeEnvironment ? activeEnvironment._id : 'n/a'}
|
||||
environment={activeEnvironment ? activeEnvironment.data : {}}
|
||||
didChange={this._didChange}
|
||||
render={render}
|
||||
|
@ -29,6 +29,7 @@ class Shortcuts extends PureComponent {
|
||||
{this.renderHotkey('Show App Preferences', ',')}
|
||||
{this.renderHotkey('Show Workspace Settings', ',', true)}
|
||||
{this.renderHotkey('Show Request Settings', ',', true, true)}
|
||||
{this.renderHotkey('Show Keyboard Shortcuts', '?')}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
@ -34,6 +34,7 @@ import {getKeys} from '../../templating/utils';
|
||||
|
||||
const KEY_ENTER = 13;
|
||||
const KEY_COMMA = 188;
|
||||
const KEY_SLASH = 191;
|
||||
const KEY_D = 68;
|
||||
const KEY_E = 69;
|
||||
const KEY_K = 75;
|
||||
@ -88,6 +89,15 @@ class App extends PureComponent {
|
||||
trackEvent('HotKey', 'Request Settings');
|
||||
}
|
||||
}
|
||||
}, {
|
||||
meta: true,
|
||||
shift: false,
|
||||
alt: false,
|
||||
key: KEY_SLASH,
|
||||
callback: () => {
|
||||
showModal(SettingsModal, 3);
|
||||
trackEvent('HotKey', 'Settings Shortcuts');
|
||||
}
|
||||
}, {
|
||||
meta: true,
|
||||
shift: false,
|
||||
@ -230,12 +240,11 @@ class App extends PureComponent {
|
||||
* Heavily optimized render function
|
||||
*
|
||||
* @param text - template to render
|
||||
* @param strict - whether to fail on undefined context values
|
||||
* @param contextCacheKey - if rendering multiple times in parallel, set this
|
||||
* @returns {Promise}
|
||||
* @private
|
||||
*/
|
||||
async _handleRenderText (text, strict = false, contextCacheKey = null) {
|
||||
async _handleRenderText (text, contextCacheKey = null) {
|
||||
if (!contextCacheKey || !this._getRenderContextPromiseCache[contextCacheKey]) {
|
||||
const context = this._fetchRenderContext();
|
||||
|
||||
@ -247,7 +256,7 @@ class App extends PureComponent {
|
||||
setTimeout(() => delete this._getRenderContextPromiseCache[contextCacheKey], 5000);
|
||||
|
||||
const context = await this._getRenderContextPromiseCache[contextCacheKey];
|
||||
return render.render(text, context, strict);
|
||||
return render.render(text, context);
|
||||
}
|
||||
|
||||
_handleGenerateCodeForActiveRequest () {
|
||||
|
@ -14,6 +14,7 @@ environment:
|
||||
install:
|
||||
- ps: Install-Product node $env:nodejs_version $env:Platform
|
||||
- npm install -g npm@latest > Nul
|
||||
- npm config set msvs_version 2013
|
||||
- npm install > NUL
|
||||
|
||||
cache:
|
||||
|
Loading…
Reference in New Issue
Block a user