-
Notifications
You must be signed in to change notification settings - Fork 623
Expand file tree
/
Copy pathHttpParsingLogHandling.js
More file actions
30 lines (26 loc) · 1.05 KB
/
HttpParsingLogHandling.js
File metadata and controls
30 lines (26 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const uWS = require('../src/uws.js');
const app = uWS.App({
// Optional SSL configuration
}).log((req, httpStatus, responseBody) => {
console.log('HTTP parsing error occurred with status:', httpStatus);
if (req) {
console.log('Request URL:', req.getUrl());
console.log('Request method:', req.getMethod());
console.log('Request headers:', req.getHeader('host'));
} else {
console.log('Request information not available (parsing failed early)');
}
// Log the response body that will be sent to the client
console.log('Response body length:', responseBody.byteLength);
console.log('Response preview:', Buffer.from(responseBody).toString().substring(0, 100) + '...');
// High-level program can now handle the error gracefully
// The socket will be closed automatically after this handler runs
}).get('/*', (res, req) => {
res.end('Hello World!');
}).listen(9001, (token) => {
if (token) {
console.log('Listening to port 9001 with HTTP parsing error handling');
} else {
console.log('Failed to listen to port 9001');
}
});