Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: support different content types #814

Merged
merged 9 commits into from
Feb 3, 2021
2 changes: 1 addition & 1 deletion config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ module.exports = function (webpackEnv) {
maxChunks: 1,
}),
new MonacoWebpackPlugin({
languages: ['json', 'javascript', 'java', 'objective-c', 'csharp']
languages: ['json', 'javascript', 'java', 'objective-c', 'csharp', 'html']
}),
// Generates an `index.html` file with the <script> injected.
new HtmlWebpackPlugin(
Expand Down
13 changes: 6 additions & 7 deletions src/app/services/actions/query-action-creator-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ export function isImageResponse(contentType: string | undefined) {
}

export function getContentType(headers: Headers) {
const full = headers.get('content-type');
if (full) {
const delimiterPos = full.indexOf(';');
const contentType = headers.get('content-type');
if (contentType) {
const delimiterPos = contentType.indexOf(';');
if (delimiterPos !== -1) {
return full.substr(0, delimiterPos);
return contentType.substr(0, delimiterPos);
} else {
return full;
return contentType;
}
}
}
Expand All @@ -81,8 +81,7 @@ export function parseResponse(response: any, respHeaders: any): Promise<any> {
return response.json();

case ContentType.XML:
return response.text();

case ContentType.HTML:
case ContentType.TextPlain:
return response.text();

Expand Down
5 changes: 4 additions & 1 deletion src/app/views/query-response/response/Response.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function getContentType(headers: any) {
*/
const splitContentTypes = contentTypes.split(';');
if (splitContentTypes.length > 0) {
contentType = splitContentTypes[0];
contentType = splitContentTypes[0].toLowerCase();
}
}
return contentType;
Expand All @@ -52,6 +52,9 @@ function displayComponent(properties: any) {
case ContentType.XML:
return <Monaco body={formatXml(body)} language='xml' height={height} />;

case ContentType.HTML:
return <Monaco body={body} language='html' height={height} />;

default:
if (isImageResponse(contentType)) {
return <Image
Expand Down
4 changes: 3 additions & 1 deletion src/types/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export enum ContentType {
XML = 'application/xml',
Json = 'application/json',
Image = 'image/jpeg',
TextPlain = 'text/plain'
TextPlain = 'text/plain',
HTML = 'text/html',
BinaryResponse = 'application/octet-stream',
}

export enum AppTheme {
Expand Down