diff --git a/app/ui/components/dropdowns/preview-mode-dropdown.js b/app/ui/components/dropdowns/preview-mode-dropdown.js index 58f4209b5..2a0c166b2 100644 --- a/app/ui/components/dropdowns/preview-mode-dropdown.js +++ b/app/ui/components/dropdowns/preview-mode-dropdown.js @@ -22,7 +22,7 @@ class PreviewModeDropdown extends PureComponent { } render () { - const {download} = this.props; + const {download, fullDownload} = this.props; return ( @@ -33,7 +33,11 @@ class PreviewModeDropdown extends PureComponent { Actions - Save to File + Save Response Body + + + + Save Full Response ); @@ -44,6 +48,7 @@ PreviewModeDropdown.propTypes = { // Functions updatePreviewMode: PropTypes.func.isRequired, download: PropTypes.func.isRequired, + fullDownload: PropTypes.func.isRequired, // Required previewMode: PropTypes.string.isRequired diff --git a/app/ui/components/response-pane.js b/app/ui/components/response-pane.js index ea59d4865..a00c37058 100644 --- a/app/ui/components/response-pane.js +++ b/app/ui/components/response-pane.js @@ -57,7 +57,7 @@ class ResponsePane extends PureComponent { const extension = mime.extension(contentType) || ''; const options = { - title: 'Save Response', + title: 'Save Response Body', buttonLabel: 'Save', filters: [{ name: 'Download', extensions: [extension] @@ -81,6 +81,46 @@ class ResponsePane extends PureComponent { }); } + async _handleDownloadFullResponseBody () { + if (!this.state.response) { + // Should never happen + console.warn('No response to download'); + return; + } + + const {body, timeline, encoding} = this.state.response; + const headers = timeline + .filter(v => v.name === 'HEADER_IN') + .map(v => v.value) + .join(''); + const bodyBuffer = new Buffer(body, encoding); + const fullResponse = `${headers}${bodyBuffer}`; + + const options = { + title: 'Save Full Response', + buttonLabel: 'Save', + filters: [{ + name: 'Download' + }] + }; + + remote.dialog.showSaveDialog(options, filename => { + if (!filename) { + trackEvent('Response', 'Save Full Cancel'); + return; + } + + fs.writeFile(filename, fullResponse, {}, err => { + if (err) { + console.warn('Failed to save full response', err); + trackEvent('Response', 'Save Full Failure'); + } else { + trackEvent('Response', 'Save Full Success'); + } + }); + }); + } + componentWillReceiveProps (nextProps) { const activeRequestId = nextProps.request ? nextProps.request._id : null; const activeResponseId = nextProps.activeResponseId; @@ -202,6 +242,7 @@ class ResponsePane extends PureComponent {