Skip to content

Commit

Permalink
Fixed content-length on uploads (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
gschier committed Apr 9, 2017
1 parent 62719f3 commit 59e396e
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/common/misc.js
Expand Up @@ -228,7 +228,7 @@ export function describeByteSize (bytes) {
unit = 'GB';
}

const rounded = Math.round(size * 10) / 10;
const rounded = (Math.round(size * 10) / 10);
return `${rounded} ${unit}`;
}

Expand Down
18 changes: 14 additions & 4 deletions app/network/network.js
@@ -1,5 +1,6 @@
import electron from 'electron';
import mkdirp from 'mkdirp';
import mimes from 'mime-types';
import {parse as urlParse} from 'url';
import {Curl} from 'node-libcurl';
import {join as pathJoin} from 'path';
Expand Down Expand Up @@ -101,7 +102,7 @@ export function _actuallySend (renderedRequest, workspace, settings) {

// Ignore the possibly large data messages
if (infoType === Curl.info.debug.DATA_OUT) {
if (content.length < 2000) {
if (content.length < 1000) {
timeline.push({name, value: content});
} else {
timeline.push({name, value: `(${describeByteSize(content.length)} hidden)`});
Expand Down Expand Up @@ -290,21 +291,23 @@ export function _actuallySend (renderedRequest, workspace, settings) {
}

// Build the body
let noBody = false;
if (renderedRequest.body.mimeType === CONTENT_TYPE_FORM_URLENCODED) {
const d = querystring.buildFromParams(renderedRequest.body.params || [], true);
setOpt(Curl.option.POSTFIELDS, d); // Send raw data
} else if (renderedRequest.body.mimeType === CONTENT_TYPE_FORM_DATA) {
const data = renderedRequest.body.params.map(param => {
if (param.type === 'file' && param.fileName) {
return {name: param.name, file: param.fileName};
return {name: param.name, file: param.fileName, type: mimes.lookup(param.fileName)};
} else {
return {name: param.name, contents: param.value};
}
});
setOpt(Curl.option.HTTPPOST, data);
} else if (renderedRequest.body.fileName) {
const fd = fs.openSync(renderedRequest.body.fileName, 'r');
headers.push({name: 'Expect', value: ''}); // Don't use Expect: 100-continue
const {size} = fs.statSync(renderedRequest.body.fileName);
headers.push({name: 'Content-Length', value: `${size}`});
const fd = fs.openSync(renderedRequest.body.fileName, 'r+');
setOpt(Curl.option.UPLOAD, 1);
setOpt(Curl.option.READDATA, fd);
const fn = () => fs.closeSync(fd);
Expand All @@ -314,6 +317,13 @@ export function _actuallySend (renderedRequest, workspace, settings) {
setOpt(Curl.option.POSTFIELDS, renderedRequest.body.text);
} else {
// No body
noBody = true;
}

if (!noBody) {
// Don't chunk uploads
headers.push({name: 'Expect', value: ''});
headers.push({name: 'Transfer-Encoding', value: ''});
}

// Build the body
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
@@ -1,7 +1,7 @@
{
"private": true,
"name": "insomnia",
"version": "5.0.2",
"version": "5.0.3",
"productName": "Insomnia",
"longName": "Insomnia REST Client",
"description": "Debug APIs like a human, not a robot",
Expand Down
23 changes: 21 additions & 2 deletions app/ui/components/codemirror/one-line-editor.js
@@ -1,4 +1,5 @@
import React, {PureComponent, PropTypes} from 'react';
import ReactDOM from 'react-dom';
import autobind from 'autobind-decorator';
import CodeEditor from './code-editor';
import Input from '../base/debounced-input';
Expand Down Expand Up @@ -61,6 +62,26 @@ class OneLineEditor extends PureComponent {
}
}

componentDidMount () {
document.body.addEventListener('click', this._handleDocumentClick);
}

componentWillUnmount () {
document.body.removeEventListener('click', this._handleDocumentClick);
}

_handleDocumentClick (e) {
if (!this._editor) {
return;
}

const node = ReactDOM.findDOMNode(this._editor);
const clickWasOutsideOfComponent = !node.contains(e.target);
if (clickWasOutsideOfComponent) {
this._editor.clearSelection();
}
}

_handleInputDragEnter () {
this._convertToEditorPreserveFocus();
}
Expand Down Expand Up @@ -149,8 +170,6 @@ class OneLineEditor extends PureComponent {
// Set focused state
this._editor.removeAttribute('data-focused');

this._editor.clearSelection();

if (!this.props.forceEditor) {
// Convert back to input sometime in the future.
// NOTE: this was originally added because the input would disappear if
Expand Down
2 changes: 1 addition & 1 deletion app/ui/components/dropdowns/content-type-dropdown.js
Expand Up @@ -29,7 +29,7 @@ class ContentTypeDropdown extends PureComponent {

const willBeFile = mimeType === CONTENT_TYPE_FILE;
const willBeMultipart = mimeType === CONTENT_TYPE_FORM_DATA;
const willBeEmpty = !mimeType;
const willBeEmpty = typeof mimeType !== 'string';

const willConvertToText = !willBeFile && !willBeMultipart && !willBeEmpty;
const willPreserveText = willConvertToText && isText;
Expand Down
11 changes: 11 additions & 0 deletions package.json
Expand Up @@ -86,6 +86,17 @@
"AppImage",
"deb"
]
},
"deb": {
"depends": [
"gconf2",
"gconf-service",
"libnotify4",
"libappindicator1",
"libxtst6",
"libnss3",
"libcurl3"
]
}
},
"dependencies": {
Expand Down

0 comments on commit 59e396e

Please sign in to comment.