This commit is contained in:
手瓜一十雪
2025-02-09 12:53:10 +08:00
parent a167aaf55f
commit 9e51a661a4

View File

@@ -45,13 +45,30 @@ export class OB11HttpServerAdapter extends IOB11NetworkAdapter<HttpServerConfig>
this.app = undefined; this.app = undefined;
} }
private isFinished(req: Request): boolean {
return req.complete;
}
private hasbody(req: Request): boolean {
return req.headers['content-length'] !== undefined && req.headers['content-length'] !== '0';
}
private initializeServer() { private initializeServer() {
this.app = express(); this.app = express();
this.server = http.createServer(this.app); this.server = http.createServer(this.app);
this.app.use(cors()); this.app.use(cors());
this.app.use(express.urlencoded({ extended: true, limit: '5000mb' })); this.app.use(express.urlencoded({ extended: true, limit: '5000mb' }));
this.app.use((req, res, next) => { this.app.use((req, res, next) => {
if (this.isFinished(req)) {
next()
return
}
if (!this.hasbody(req)) {
next()
return
}
// 兼容处理没有带content-type的请求 // 兼容处理没有带content-type的请求
req.headers['content-type'] = 'application/json'; req.headers['content-type'] = 'application/json';
let rawData = ''; let rawData = '';
@@ -98,7 +115,7 @@ export class OB11HttpServerAdapter extends IOB11NetworkAdapter<HttpServerConfig>
if (req.method == 'get') { if (req.method == 'get') {
payload = req.query; payload = req.query;
} else if (req.query) { } else if (req.query) {
payload = { ...req.query, ...req.body }; payload = { ...req.body, ...req.query };
} }
if (req.path === '' || req.path === '/') { if (req.path === '' || req.path === '/') {
const hello = OB11Response.ok({}); const hello = OB11Response.ok({});