From 7dce5ce3c3e7d27b5371dba26e1e94bed0415682 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Fri, 22 Jul 2016 13:38:28 -0700 Subject: [PATCH] Renamed some response params and fixed relative webview urls --- app/components/ResponseBodyViewer.js | 4 +--- app/components/ResponsePane.js | 4 ++-- app/database/index.js | 4 ++-- app/lib/network.js | 29 ++++++++++++---------------- app/lib/render.js | 5 +++++ 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/app/components/ResponseBodyViewer.js b/app/components/ResponseBodyViewer.js index f337864e3..8cce554fb 100644 --- a/app/components/ResponseBodyViewer.js +++ b/app/components/ResponseBodyViewer.js @@ -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; diff --git a/app/components/ResponsePane.js b/app/components/ResponsePane.js index 9cd372cef..35a882324 100644 --- a/app/components/ResponsePane.js +++ b/app/components/ResponsePane.js @@ -86,8 +86,8 @@ class ResponsePane extends Component { statusCode={response.statusCode} statusMessage={response.statusMessage} /> - - + + )} diff --git a/app/database/index.js b/app/database/index.js index 1f2afd016..657b6f93d 100644 --- a/app/database/index.js +++ b/app/database/index.js @@ -55,8 +55,8 @@ const MODEL_DEFAULTS = { statusMessage: '', contentType: 'text/plain', url: '', - bytes: 0, - millis: 0, + bytesRead: 0, + elapsedTime: 0, headers: [], body: '', error: '' diff --git a/app/lib/network.js b/app/lib/network.js index 5d9bd4c4b..a3c7dd649 100644 --- a/app/lib/network.js +++ b/app/lib/network.js @@ -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}; }) }; diff --git a/app/lib/render.js b/app/lib/render.js index 860b9fad0..495c5dab9 100644 --- a/app/lib/render.js +++ b/app/lib/render.js @@ -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)); } });