mirror of
https://github.com/wukko/cobalt.git
synced 2024-06-26 17:06:48 +01:00
Accept header 'application/json' with utf8 charset
This commit is contained in:
parent
156372a1ef
commit
b1adbd659e
|
@ -67,7 +67,7 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) {
|
||||||
|
|
||||||
app.use('/api/json', express.json({
|
app.use('/api/json', express.json({
|
||||||
verify: (req, res, buf) => {
|
verify: (req, res, buf) => {
|
||||||
let acceptCon = String(req.header('Accept')) === "application/json";
|
let acceptCon = String(req.header('Accept')) === "application/json" || String(req.header('Accept')) === "application/json; charset=utf-8";
|
||||||
if (acceptCon) {
|
if (acceptCon) {
|
||||||
if (buf.length > 720) throw new Error();
|
if (buf.length > 720) throw new Error();
|
||||||
JSON.parse(buf);
|
JSON.parse(buf);
|
||||||
|
@ -80,7 +80,7 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) {
|
||||||
// handle express.json errors properly (https://github.com/expressjs/express/issues/4065)
|
// handle express.json errors properly (https://github.com/expressjs/express/issues/4065)
|
||||||
app.use('/api/json', (err, req, res, next) => {
|
app.use('/api/json', (err, req, res, next) => {
|
||||||
let errorText = "invalid json body";
|
let errorText = "invalid json body";
|
||||||
let acceptCon = String(req.header('Accept')) !== "application/json";
|
let acceptCon = String(req.header('Accept')) !== "application/json" && String(req.header('Accept')) !== "application/json; charset=utf-8";
|
||||||
|
|
||||||
if (err || acceptCon) {
|
if (err || acceptCon) {
|
||||||
if (acceptCon) errorText = "invalid accept header";
|
if (acceptCon) errorText = "invalid accept header";
|
||||||
|
@ -98,7 +98,7 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) {
|
||||||
let lang = languageCode(req);
|
let lang = languageCode(req);
|
||||||
let j = apiJSON(0, { t: "bad request" });
|
let j = apiJSON(0, { t: "bad request" });
|
||||||
try {
|
try {
|
||||||
let contentCon = String(req.header('Content-Type')) === "application/json";
|
let contentCon = String(req.header('Accept')) === "application/json" || String(req.header('Accept')) === "application/json; charset=utf-8";
|
||||||
let request = req.body;
|
let request = req.body;
|
||||||
if (contentCon && request.url) {
|
if (contentCon && request.url) {
|
||||||
request.dubLang = request.dubLang ? lang : false;
|
request.dubLang = request.dubLang ? lang : false;
|
||||||
|
|
Loading…
Reference in a new issue