|
@@ -174,6 +174,14 @@ export const createServer = (backendState: BackendState, serverParams = {} as Cr |
|
|
decorateRequestWithBackend(backendState), |
|
|
decorateRequestWithBackend(backendState), |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
const isTextMediaType = (mediaType: string) => ( |
|
|
|
|
|
mediaType.startsWith('text/') |
|
|
|
|
|
|| [ |
|
|
|
|
|
'application/json', |
|
|
|
|
|
'application/xml' |
|
|
|
|
|
].includes(mediaType) |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
const processRequest = (middlewares: [string, Middleware, v.BaseSchema?][]) => async (req: RequestContext) => { |
|
|
const processRequest = (middlewares: [string, Middleware, v.BaseSchema?][]) => async (req: RequestContext) => { |
|
|
if (req.url === '/' || req.url === '') { |
|
|
if (req.url === '/' || req.url === '') { |
|
|
return handleGetRoot(req); |
|
|
return handleGetRoot(req); |
|
@@ -220,10 +228,19 @@ export const createServer = (backendState: BackendState, serverParams = {} as Cr |
|
|
|
|
|
|
|
|
if (schema) { |
|
|
if (schema) { |
|
|
const contentTypeHeader = req.headers['content-type'] ?? 'application/octet-stream'; |
|
|
const contentTypeHeader = req.headers['content-type'] ?? 'application/octet-stream'; |
|
|
const fragments = contentTypeHeader.split(';'); |
|
|
|
|
|
|
|
|
const fragments = contentTypeHeader.replace(/\s+/g, ' ').split(';'); |
|
|
const mediaType = fragments[0]; |
|
|
const mediaType = fragments[0]; |
|
|
const charsetParam = fragments.map((s) => s.trim()) |
|
|
|
|
|
.find((f) => f.startsWith('charset=')) ?? (mediaType.startsWith('text/') ? 'charset=utf-8' : 'charset=binary'); |
|
|
|
|
|
|
|
|
const charsetParam = ( |
|
|
|
|
|
fragments |
|
|
|
|
|
.map((s) => s.trim()) |
|
|
|
|
|
.find((f) => f.startsWith('charset=')) |
|
|
|
|
|
|
|
|
|
|
|
?? ( |
|
|
|
|
|
isTextMediaType(mediaType) |
|
|
|
|
|
? 'charset=utf-8' |
|
|
|
|
|
: 'charset=binary' |
|
|
|
|
|
) |
|
|
|
|
|
); |
|
|
const [_charsetKey, charsetRaw] = charsetParam.split('=').map((s) => s.trim()); |
|
|
const [_charsetKey, charsetRaw] = charsetParam.split('=').map((s) => s.trim()); |
|
|
const charset = ( |
|
|
const charset = ( |
|
|
( |
|
|
( |
|
|