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, previewMode: PropTypes.string.isRequired,
editorFontSize: PropTypes.number.isRequired, editorFontSize: PropTypes.number.isRequired,
editorLineWrapping: PropTypes.bool.isRequired, editorLineWrapping: PropTypes.bool.isRequired,
url: PropTypes.string.isRequired
// Optional
url: PropTypes.string
}; };
export default ResponseViewer; export default ResponseViewer;

View File

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

View File

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

View File

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

View File

@ -45,6 +45,11 @@ export function getRenderedRequest (request) {
throw new Error(`Parse Failed: "${e.message}"`); 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)); return new Promise(resolve => resolve(renderedRequest));
} }
}); });