Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #142 from apiaryio/honzajavorek/update-deps
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
honzajavorek authored May 6, 2019
2 parents 0a39d93 + 54d7adc commit 01cf9da
Show file tree
Hide file tree
Showing 3 changed files with 2,925 additions and 914 deletions.
25 changes: 16 additions & 9 deletions lib/mixins/validatable-http-message.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const jph = require('json-parse-helpfulerror');
const mediaTyper = require('media-typer');
const contentType = require('content-type');
const isset = require('../utils/isset');
const validators = require('../validators');

Expand Down Expand Up @@ -424,17 +425,23 @@ but body is not a parseable JSON:\n${error.message}\
);
}

isJsonContentType(contentType) {
if (!contentType) {
isJsonContentType(contentTypeValue) {
if (!contentTypeValue) {
return false;
}
try {
const { type } = contentType.parse(`${contentTypeValue}`);
const parsed = mediaTyper.parse(type);
return (
(parsed.type === 'application' && parsed.subtype === 'json')
|| parsed.suffix === 'json'
);
} catch (e) {
// The Content-Type value is basically a user input, it can be any
// kind of rubbish, and it is neither this function's nor Gavel's problem
// if it's invalid
return false;
}

const parsed = mediaTyper.parse(`${contentType}`);
const isJson =
(parsed.type === 'application' && parsed.subtype === 'json') ||
parsed.suffix === 'json';

return isJson;
}
}

Expand Down
Loading

0 comments on commit 01cf9da

Please sign in to comment.