Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/core/components/highlight-code.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export default class HighlightCode extends Component {
static propTypes = {
value: PropTypes.string.isRequired,
className: PropTypes.string,
downloadable: PropTypes.bool
downloadable: PropTypes.bool,
fileName: PropTypes.string
}

componentDidMount() {
Expand All @@ -23,7 +24,7 @@ export default class HighlightCode extends Component {
}

downloadText = () => {
saveAs(this.props.value, "response.txt")
saveAs(this.props.value, this.props.fileName || "response.txt")
}

preventYScrollingBeyondElement = (e) => {
Expand Down
11 changes: 6 additions & 5 deletions src/core/components/response-body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default class ResponseBody extends React.PureComponent {
let { content, contentType, url, headers={}, getComponent } = this.props
const { parsedContent } = this.state
const HighlightCode = getComponent("highlightCode")
const downloadName = "response_" + new Date().getTime()
let body, bodyEl
url = url || ""

Expand Down Expand Up @@ -100,19 +101,19 @@ export default class ResponseBody extends React.PureComponent {
body = "can't parse JSON. Raw result:\n\n" + content
}

bodyEl = <HighlightCode downloadable value={ body } />
bodyEl = <HighlightCode downloadable fileName={`${downloadName}.json`} value={ body } />

// XML
} else if (/xml/i.test(contentType)) {
body = formatXml(content, {
textNodesOnSameLine: true,
indentor: " "
})
bodyEl = <HighlightCode downloadable value={ body } />
bodyEl = <HighlightCode downloadable fileName={`${downloadName}.xml`} value={ body } />

// HTML or Plain Text
} else if (lowerCase(contentType) === "text/html" || /text\/plain/.test(contentType)) {
bodyEl = <HighlightCode downloadable value={ content } />
bodyEl = <HighlightCode downloadable fileName={`${downloadName}.html`} value={ content } />

// Image
} else if (/^image\//i.test(contentType)) {
Expand All @@ -126,7 +127,7 @@ export default class ResponseBody extends React.PureComponent {
} else if (/^audio\//i.test(contentType)) {
bodyEl = <pre><audio controls><source src={ url } type={ contentType } /></audio></pre>
} else if (typeof content === "string") {
bodyEl = <HighlightCode downloadable value={ content } />
bodyEl = <HighlightCode downloadable fileName={`${downloadName}.txt`} value={ content } />
} else if ( content.size > 0 ) {
// We don't know the contentType, but there was some content returned
if(parsedContent) {
Expand All @@ -136,7 +137,7 @@ export default class ResponseBody extends React.PureComponent {
<p className="i">
Unrecognized response type; displaying content as text.
</p>
<HighlightCode downloadable value={ parsedContent } />
<HighlightCode downloadable fileName={`${downloadName}.txt`} value={ parsedContent } />
</div>

} else {
Expand Down