Skip to content

Commit

Permalink
postmerge #216
Browse files Browse the repository at this point in the history
  • Loading branch information
mishushakov committed May 1, 2024
1 parent dea2774 commit bec3e4f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stepci",
"version": "2.8.0",
"version": "2.8.1",
"description": "Automated API Testing and Quality Assurance",
"main": "index.js",
"bin": {
Expand Down
18 changes: 9 additions & 9 deletions src/lib/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ function renderSpaces (spaces: number) {
}

function shouldDisplayBody(contentType: string | undefined): boolean {
// Treat empty content-type as displayable
if (!contentType) {
// Treat empty content-type as displayable
return true;
}
return true
}

const displayableTypes: RegExp[] = [
/^text\//, // Matches any MIME type starting with "text/"
/application\/(x-)?(json|xml|csv|javascript|ecmascript)/, // Matches both standard and non-standard textual application types
/application\/.*\+(json|xml)$/, // Matches MIME types that end with +json or +xml
];
]

// Normalize content type to handle cases with parameters like charset
const normalizedType = contentType.split(';')[0].trim();

return displayableTypes.some(pattern => pattern.test(normalizedType));
const normalizedType = contentType.split(';')[0].trim()
return displayableTypes.some(pattern => pattern.test(normalizedType))
}

function renderHTTPRequest (request: HTTPStepRequest) {
Expand All @@ -55,12 +55,12 @@ function renderHTTPRequest (request: HTTPStepRequest) {
function renderHTTPResponse (response: HTTPStepResponse) {
const responseHeaders = response.headers ? Object.keys(response.headers).map(header => `${header}: ${response.headers ? response.headers[header] : ''}\n`) : ''
let responseBody
if (shouldDisplayBody(response.contentType || undefined) || process.env.STEPCI_DISPLAY_ALL_CONTENT_TYPES) {
if (shouldDisplayBody(response.contentType || undefined)) {
responseBody = '\n' + Buffer.from(response.body).toString()
}

else {
responseBody = '\n[Response body not displayed due to Content-Type (Use STEPCI_DISPLAY_ALL_CONTENT_TYPES=1 to force display)]'
responseBody = '\nResponse body not displayed due to unsupported Content-Type'
}

return `${response.protocol} ${response.status} ${response.statusText}\n${responseHeaders.toString().replaceAll(',', '')}${responseBody}`
Expand Down

0 comments on commit bec3e4f

Please sign in to comment.