Skip to content

Commit

Permalink
Fix: support different content types (#814)
Browse files Browse the repository at this point in the history
* add html and octet stream content types to enum

* add html to available languages in the plugin

* fallback to showing text

* explicitly set the response for each response type

* make editor readonly
  • Loading branch information
thewahome committed Feb 3, 2021
1 parent 4542cbe commit ccd8702
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
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
9 changes: 6 additions & 3 deletions src/app/views/query-response/response/Response.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function getContentType(headers: any) {
*/
const splitContentTypes = contentTypes.split(';');
if (splitContentTypes.length > 0) {
contentType = splitContentTypes[0];
contentType = splitContentTypes[0].toLowerCase();
}
}
return contentType;
Expand All @@ -51,7 +51,10 @@ function displayComponent(properties: any) {

switch (contentType) {
case ContentType.XML:
return <Monaco body={formatXml(body)} language='xml' height={height} />;
return <Monaco body={formatXml(body)} language='xml' readOnly={true} height={height} />;

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

default:
if (isImageResponse(contentType)) {
Expand All @@ -61,7 +64,7 @@ function displayComponent(properties: any) {
alt='profile image'
/>;
}
return <Monaco body={body} language={language} height={height} />;
return <Monaco body={body} readOnly={true} language={language} height={height} />;
}
}

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

0 comments on commit ccd8702

Please sign in to comment.