Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 44 additions & 10 deletions frameworks/fulmine/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ const registerJsonRoute = (target, path = '/json/:count', ...before) => target.g
res.json({ items, count });
});

const registerEchoRoute = (target) => target.post('/echo', readRaw, (req, res) => {
// an empty body leaves req.body unset
// an empty body leaves req.body unset
const echo = (req, res) => {
res.type('application/octet-stream').send(Buffer.isBuffer(req.body) ? req.body : Buffer.alloc(0));
});
};
const registerEchoRoute = (target) => target.post('/echo', readRaw, echo);

// The .br and .gz files on disk are served when the client accepts them.
// https://fulmine.sndesign.it/examples/static-precompressed
Expand Down Expand Up @@ -216,13 +217,40 @@ app.get('/fortunes', async (req, res) => {
});
}

// /spec, the compliance route: Http11Probe reads it on 8080, h2spec on 8082 and 8443.
// HEAD goes to the GET handler, as on Express.
const specHeaders = (req, res) => {
const raw = req.rawHeaders;
let out = '';
for (let i = 0; i < raw.length; i += 2) out += raw[i] + ': ' + raw[i + 1] + '\n';
res.type('text/plain').send(out);
};
app.get('/spec', (req, res) => {
res.type('text/plain').send('spec ok');
});
app.options('/spec', readRaw, (req, res) => {
res.set('allow', 'GET, HEAD, POST, OPTIONS').end();
});
app.post('/spec', readRaw, echo);
app.get('/spec/headers', specHeaders);
app.post('/spec/headers', readRaw, specHeaders);

// /parse, for the resilience suite: each body goes through the parser of its type. The limits
// are the parsers' defaults, a body over them is a 413 and an invalid one a 400.
app.post('/parse',
express.json(), express.urlencoded(), express.multipart(), express.raw({ type: () => true }),
(req, res) => {
res.type('text/plain').send('ok');
});

// No error middleware on purpose: one anywhere in the app takes the fast paths off every route,
// and the final handler already answers 400, 404 and 413 with the status the profiles expect.

// app.uwsApp.ws and not app.ws: the echo needs no Request object on the upgrade.
// https://fulmine.sndesign.it/websockets
// 64 KB: the Autobahn cases of the spec suite echo messages up to that size.
app.uwsApp.ws('/ws', {
maxPayloadLength: 16 * 1024,
maxPayloadLength: 64 * 1024,
message: (ws, message, isBinary) => ws.send(message, isBinary)
});

Expand Down Expand Up @@ -275,13 +303,19 @@ if (hasPair('/certs-tls')) {
setInterval(() => {
const now = pairStamp();
if (!now || now === stamp) return;
stamp = now;
const next = tlsApp('/certs-tls');
next.listen(9000, (e) => {
if (e) return;
live.close();
live = next;
});
try {
next.listen(9000, (e) => {
if (e) return;
live.close();
live = next;
});
} catch {
// listen() builds the SSL context: mid-swap the key and the certificate do not
// match yet and it throws, so the next tick tries again
return;
}
stamp = now;
}, 1000).unref();
});
}
Expand Down
2 changes: 2 additions & 0 deletions frameworks/fulmine/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"repo": "https://github.com/nigrosimone/fulmine.js",
"website": "https://fulmine.sndesign.it/",
"enabled": true,
"resilience": true,
"spec": ["h1", "h2", "ws"],
"tls_check": true,
"tests": [
"baseline", "latency-1m", "latency-10k", "latency-500k-8cpu",
Expand Down
2 changes: 1 addition & 1 deletion frameworks/fulmine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "httparena-fulmine",
"private": true,
"dependencies": {
"fulmine.js": "^5.27.0",
"fulmine.js": "^5.34.1",
"pg": "^8.13.0",
"pg-native": "^3.8.0",
"ejs": "^3.1.10",
Expand Down
Loading
Loading