-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' into feature/body-types
- Loading branch information
Showing
33 changed files
with
585 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
# Execute from the root of the git repo | ||
|
||
rm -rf node_modules RESTED.* dist/rested* coverage | ||
cd .. | ||
zip -r -9 RESTED/RESTED.src.zip RESTED | ||
cd RESTED | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React, { PropTypes } from 'react'; | ||
import responsePropTypes, { responseShape } from 'propTypes/response'; | ||
|
||
import { StyledResponse, StyledHeader, Status } from './StyledComponents'; | ||
import Headers from './Headers'; | ||
|
||
function Titlebar({ url, time, onClick }) { | ||
return ( | ||
<StyledHeader expandable onClick={onClick}> | ||
<h3> | ||
Redirect ({(time / 1000).toFixed(3)}s) - <a href={url} className="text-muted">{url}</a> | ||
</h3> | ||
</StyledHeader> | ||
); | ||
} | ||
|
||
Titlebar.propTypes = { | ||
url: responseShape.url, | ||
time: responseShape.time, | ||
onClick: PropTypes.func.isRequired, | ||
}; | ||
|
||
function Redirect(props) { | ||
const { | ||
response, | ||
headers, | ||
isExpanded, | ||
setExpanded, | ||
} = props; | ||
|
||
if (!response || !headers) return null; | ||
|
||
const { method, url, time } = response; | ||
|
||
return ( | ||
<StyledResponse | ||
collapsible | ||
expanded={isExpanded} | ||
header={<Titlebar method={method} url={url} time={time} onClick={setExpanded} />} | ||
> | ||
<h3> | ||
<Status | ||
green={response.statusCode >= 200 && response.statusCode < 300} | ||
red={response.statusCode >= 400 && response.statusCode < 600} | ||
> | ||
{response.statusCode} | ||
</Status> | ||
<small> {response.statusLine.replace(/.*\d{3} /, '')}</small> | ||
</h3> | ||
|
||
<Headers expanded headers={headers} /> | ||
</StyledResponse> | ||
); | ||
} | ||
|
||
Redirect.propTypes = { | ||
response: responsePropTypes, | ||
headers: responseShape.headers, | ||
isExpanded: PropTypes.bool.isRequired, | ||
setExpanded: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default Redirect; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import React, { PropTypes } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { Alert } from 'react-bootstrap'; | ||
import Highlight from 'react-highlight'; | ||
import formatXml from 'xml-formatter'; | ||
|
||
import * as Actions from 'store/request/actions'; | ||
import { isDisabledHighlighting, isWrapResponse } from 'store/options/selectors'; | ||
import responsePropTypes, { responseShape } from 'propTypes/response'; | ||
import getContentType from 'utils/contentType'; | ||
import approximateSizeFromLength from 'utils/approximateSizeFromLength'; | ||
|
||
import { StyledResponse, StyledHeader, Status } from './StyledComponents'; | ||
import Headers from './Headers'; | ||
import RenderedResponse from './RenderedResponse'; | ||
|
||
function Titlebar({ url, time }) { | ||
return ( | ||
<StyledHeader> | ||
<h3> | ||
Response ({time}) - <a href={url} className="text-muted">{url}</a> | ||
</h3> | ||
</StyledHeader> | ||
); | ||
} | ||
|
||
Titlebar.propTypes = { | ||
url: responseShape.url, | ||
time: responseShape.time, | ||
}; | ||
|
||
export function Response(props) { | ||
const { | ||
response, | ||
highlightingDisabled, | ||
wrapResponse, | ||
redirectChain, | ||
interceptedResponse, | ||
} = props; | ||
|
||
if (!response || !interceptedResponse) return null; | ||
|
||
const { method, url, totalTime } = response; | ||
let { body } = response; | ||
|
||
let time; | ||
if (redirectChain.length > 0) { | ||
time = `${(interceptedResponse.time / 1000).toFixed(3)}s, total time ${totalTime / 1000}s`; | ||
} else { | ||
time = `${totalTime / 1000}s`; | ||
} | ||
|
||
const contentLength = interceptedResponse.responseHeaders.find(header => ( | ||
header.name.toLowerCase() === 'content-length' | ||
)); | ||
const contentType = interceptedResponse.responseHeaders.find(header => ( | ||
header.name.toLowerCase() === 'content-type' | ||
)); | ||
|
||
const contentSize = contentLength | ||
? Number(contentLength.value) | ||
: approximateSizeFromLength(body); | ||
const type = getContentType(contentType && contentType.value); | ||
|
||
try { | ||
if (type.json) { | ||
body = JSON.stringify(JSON.parse(body), null, 2); | ||
} else if (type.xml) { | ||
body = formatXml(body); | ||
} | ||
} catch (e) { | ||
// eslint-disable-next-line no-console | ||
console.warn('Encountered an error while formatting response as ' + | ||
`${contentType && contentType.value}. Falling back to plain text`, e); | ||
} | ||
|
||
return ( | ||
<StyledResponse | ||
wrapResponse={wrapResponse} | ||
header={<Titlebar method={method} url={url} time={time} />} | ||
> | ||
<h3> | ||
<Status | ||
green={response.status >= 200 && response.status < 300} | ||
red={response.status >= 400 && response.status < 600} | ||
> | ||
{response.status} | ||
</Status> | ||
<small> {response.statusText}</small> | ||
</h3> | ||
|
||
<Headers headers={interceptedResponse.responseHeaders} /> | ||
{type.html && <RenderedResponse html={body} />} | ||
|
||
{!highlightingDisabled && contentSize < 20000 | ||
? ( | ||
<Highlight> | ||
{body} | ||
</Highlight> | ||
) : ( | ||
<span> | ||
{contentSize >= 20000 && ( | ||
<Alert bsStyle="warning"> | ||
The size of the response is greater than 20KB, syntax | ||
highlighting has been disabled for performance reasons. | ||
</Alert> | ||
)} | ||
|
||
<code><pre> | ||
{body} | ||
</pre></code> | ||
</span> | ||
) | ||
} | ||
</StyledResponse> | ||
); | ||
} | ||
|
||
Response.propTypes = { | ||
response: responsePropTypes, | ||
highlightingDisabled: PropTypes.bool.isRequired, | ||
wrapResponse: PropTypes.bool.isRequired, | ||
redirectChain: PropTypes.arrayOf().isRequired, | ||
interceptedResponse: PropTypes.shape({}), | ||
}; | ||
|
||
const mapStateToProps = state => ({ | ||
highlightingDisabled: isDisabledHighlighting(state), | ||
wrapResponse: isWrapResponse(state), | ||
}); | ||
|
||
export default connect(mapStateToProps, Actions)(Response); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.