Skip to content

Commit

Permalink
[APIDEVP-6221] Add ability to guess raw language type
Browse files Browse the repository at this point in the history
  • Loading branch information
rutvik-gs committed Apr 16, 2024
1 parent a73189e commit ba9ce4e
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@ const commander = require('commander'),
UserError = require('./UserError'),
{ USER_ERRORS } = require('./constants'),
formDataOptions = ['-d', '--data', '--data-raw', '--data-binary', '--data-ascii'],
allowedOperators = ['<', '>', '(', ')'];
allowedOperators = ['<', '>', '(', ')'],
REQUEST_BODY_LANGUAGE_TEXT = 'text',
REQUEST_BODY_LANGUAGE_JSON = 'json',
REQUEST_BODY_LANGUAGE_JAVASCRIPT = 'javascript',
REQUEST_BODY_LANGUAGE_HTML = 'html',
REQUEST_BODY_LANGUAGE_XML = 'xml',
LANGUAGE_REGEX_MATCH = {
[REQUEST_BODY_LANGUAGE_JSON]: /^application\/(\S+\+)?json/,
[REQUEST_BODY_LANGUAGE_JAVASCRIPT]: /^(text|application)\/(\S+\+)?javascript/,
[REQUEST_BODY_LANGUAGE_XML]: /^(text|application)\/(\S+\+)?xml/,
[REQUEST_BODY_LANGUAGE_HTML]: /^text\/html/
};

var program,

Expand Down Expand Up @@ -838,6 +849,14 @@ var program,
else {
request.body.mode = 'raw';
request.body.raw = rawDataString;

request.body.options = {};
request.body.options.raw = {};
request.body.options.raw.language = Object.keys(LANGUAGE_REGEX_MATCH)
.find((key) => {
return LANGUAGE_REGEX_MATCH[key].test(content_type);
}) || REQUEST_BODY_LANGUAGE_TEXT;

}

urlData = request.data;
Expand Down

0 comments on commit ba9ce4e

Please sign in to comment.