Express: Set max SSL fragment size in Express

Created on 11 Sep 2016  路  4Comments  路  Source: expressjs/express

I'm using express to set up an HTTPS server for some embedded devices. However, due to the lack of computing capabilities, the default SSL fragment size 16384 is too large for these devices. I wonder how I can change this size in express.
I found that in tls modules, TLSSocket class has a method _tlsSocket.setMaxSendFragment(size)_ which may work, but I can't find out how to use it in Express.
This is how my server is established:

var app = require('express')();
var cert_path = '/home/houlu/Programs/Node/http/ssl/';
var privateKey = fs.readFileSync(cert_path+'server.key', 'utf8');
var certificate = fs.readFileSync(cert_path+'server.crt', 'utf8');
var credentials = {key: privateKey, cert: certificate};

httpsServer = https.createServer(credentials, app);

Thanks a lot! :-)

question

All 4 comments

Since this is a socket-level option, this would be handled outside of Express, since Express is request/response-level (multiple request/response pairs can share a single socket).

I think the following would work (not 100% sure, as the Node.js documentation isn't very clear, and I'm not at a computer to test), assuming you wanted all sockets to have this setting:

var app = require('express')();
var cert_path = '/home/houlu/Programs/Node/http/ssl/';
var privateKey = fs.readFileSync(cert_path+'server.key', 'utf8');
var certificate = fs.readFileSync(cert_path+'server.crt', 'utf8');
var credentials = {key: privateKey, cert: certificate};

var httpsServer = https.createServer(credentials, app);

httpsServer.on('connection', function (tlsSocket) {
  tlsSocket.setMaxSendFragment(/* whatever size */);
});

Thanks a lot, I'll have a try and let you know the results.
Besides, I think it should be 'secureConnection' instead of 'connection' in HTTPS context.
:)

It works! Thanks a lot!

Awesome, good t hear! Let us know if you have any other questions :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jefflage picture jefflage  路  4Comments

ZeddYu picture ZeddYu  路  3Comments

zackarychapple picture zackarychapple  路  3Comments

HafidAbnaou picture HafidAbnaou  路  3Comments

Sunriselegacy picture Sunriselegacy  路  3Comments