feat: response size

This commit is contained in:
Anoop M D 2022-01-02 01:09:54 +05:30
parent 7a61f29acc
commit fc32f5b413
3 changed files with 17 additions and 3 deletions

View File

@ -86,11 +86,15 @@ const RequestTabPanel = ({dispatch, actions, collections, activeRequestTabId, re
console.log(headers); console.log(headers);
if(data && !errors) { if(data && !errors) {
// todo: alternate way to calculate length when content length is not present
const size = headers.map["content-length"];
dispatch({ dispatch({
type: actions.RESPONSE_RECEIVED, type: actions.RESPONSE_RECEIVED,
response: { response: {
data: data, data: data,
headers: Object.entries(headers.map), headers: Object.entries(headers.map),
size: size,
status: status, status: status,
duration: timeEnd - timeStart duration: timeEnd - timeStart
}, },

View File

@ -1,10 +1,20 @@
import React from 'react'; import React from 'react';
import StyledWrapper from './StyledWrapper'; import StyledWrapper from './StyledWrapper';
const ResponseSize = () => { const ResponseSize = ({size}) => {
let sizeToDisplay = ''
if(size > 1024 ) { // size is greater than 1kb
let kb = Math.floor(size / 1024);
let decimal = ((size % 1024) / 1024).toFixed(2) * 100;
sizeToDisplay = kb + '.' + decimal + 'KB';
} else {
sizeToDisplay = size + 'B'
}
return ( return (
<StyledWrapper className="mt-3 ml-4"> <StyledWrapper className="mt-3 ml-4">
8.31KB {sizeToDisplay}
</StyledWrapper> </StyledWrapper>
) )
}; };

View File

@ -50,7 +50,7 @@ const ResponsePane = ({rightPaneWidth, response, isLoading}) => {
<div className="flex flex-grow justify-end items-center"> <div className="flex flex-grow justify-end items-center">
<StatusCode status={response.status}/> <StatusCode status={response.status}/>
<ResponseTime duration={response.duration}/> <ResponseTime duration={response.duration}/>
<ResponseSize /> <ResponseSize size={response.size}/>
</div> </div>
) : null } ) : null }
</div> </div>