Hot fix for Surge HTTP 2.0 feature

This commit is contained in:
Peng-YM
2022-06-14 23:52:04 +08:00
parent f77aef65d8
commit f0a286e516
3 changed files with 13 additions and 4 deletions

View File

@@ -54,7 +54,8 @@ export default function express({ substore: $, port }) {
// dispatch url to route
const dispatch = (request, start = 0) => {
let { method, url, headers, body } = request;
if (/json/i.test(headers['Content-Type'])) {
headers = formatHeaders(headers);
if (/json/i.test(headers['content-type'])) {
body = JSON.parse(body);
}
@@ -214,6 +215,14 @@ export default function express({ substore: $, port }) {
}
}
function formatHeaders(headers) {
const result = {};
for (const k of Object.keys(headers)) {
result[k.toLowerCase()] = headers[k];
}
return result;
}
function patternMatched(pattern, path) {
if (pattern instanceof RegExp && pattern.test(path)) {
return true;