Renamed some response params and fixed relative webview urls

This commit is contained in:
Gregory Schier 2016-07-22 13:38:28 -07:00
parent 12bfae3592
commit 7dce5ce3c3
5 changed files with 22 additions and 24 deletions

View File

@ -52,9 +52,7 @@ ResponseViewer.propTypes = {
previewMode: PropTypes.string.isRequired,
editorFontSize: PropTypes.number.isRequired,
editorLineWrapping: PropTypes.bool.isRequired,
// Optional
url: PropTypes.string
url: PropTypes.string.isRequired
};
export default ResponseViewer;

View File

@ -86,8 +86,8 @@ class ResponsePane extends Component {
statusCode={response.statusCode}
statusMessage={response.statusMessage}
/>
<TimeTag milliseconds={response.millis}/>
<SizeTag bytes={response.bytes}/>
<TimeTag milliseconds={response.elapsedTime}/>
<SizeTag bytes={response.bytesRead}/>
</div>
)}
</header>

View File

@ -55,8 +55,8 @@ const MODEL_DEFAULTS = {
statusMessage: '',
contentType: 'text/plain',
url: '',
bytes: 0,
millis: 0,
bytesRead: 0,
elapsedTime: 0,
headers: [],
body: '',
error: ''

View File

@ -2,7 +2,6 @@ import networkRequest from 'request';
import * as db from '../database';
import * as querystring from './querystring';
import {render} from './render';
import {DEBOUNCE_MILLIS} from './constants';
import {STATUS_CODE_PEBKAC} from './constants';
import {getRenderedRequest} from './render';
@ -26,11 +25,6 @@ function buildRequestConfig (request, patch = {}) {
const qs = querystring.buildFromParams(request.parameters);
config.url = querystring.joinURL(request.url, qs);
// Default the proto if it doesn't exist
if (config.url.indexOf('://') === -1) {
config.url = `https://${config.url}`;
}
// Set basic auth if we need to
if (request.authentication.username) {
config.auth = {
@ -59,27 +53,28 @@ function actuallySend (request, settings) {
}, true);
const startTime = Date.now();
networkRequest(config, function (err, response) {
networkRequest(config, function (err, networkResponse) {
if (err) {
db.responseCreate({
parentId: request._id,
millis: Date.now() - startTime,
elapsedTime: Date.now() - startTime,
error: err.toString()
});
console.warn(`Request to ${config.url} failed`, err);
return reject(err);
}
const responsePatch = {
parentId: request._id,
statusCode: response.statusCode,
statusMessage: response.statusMessage,
contentType: response.headers['content-type'],
url: request.url,
millis: Date.now() - startTime,
bytes: response.connection.bytesRead,
body: response.body,
headers: Object.keys(response.headers).map(name => {
const value = response.headers[name];
statusCode: networkResponse.statusCode,
statusMessage: networkResponse.statusMessage,
contentType: networkResponse.headers['content-type'],
url: config.url, // TODO: Handle redirects somehow
elapsedTime: networkResponse.elapsedTime,
bytes: networkResponse.connection.bytesRead,
body: networkResponse.body,
headers: Object.keys(networkResponse.headers).map(name => {
const value = networkResponse.headers[name];
return {name, value};
})
};

View File

@ -45,6 +45,11 @@ export function getRenderedRequest (request) {
throw new Error(`Parse Failed: "${e.message}"`);
}
// Default the proto if it doesn't exist
if (renderedRequest.url.indexOf('://') === -1) {
renderedRequest.url = `http://${renderedRequest.url}`;
}
return new Promise(resolve => resolve(renderedRequest));
}
});