Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close connection instead of setting 'keep-alive'

I'm trying to disable the keep-alive setting in a very simple express app. I tried the answer from someone doing the same in an older version:

var express = require('express');
var app = express();

app.get('/', function(req, res) {
    res.set('Connection', 'close'); // attempting to override default (keep-alive)
    res.set('Proof', 'close');      // just to show that this should modify the header value
    res.send('hello');
});

var server = app.listen(3000, function() {
    console.log('Listening on port %d', server.address().port);
});

However, Connection is still set to keep-alive:

$ curl -D - http://my-test-site.com
HTTP/1.1 200 OK
Server: nginx/1.4.7
Date: Sun, 11 May 2014 08:07:51 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 5
Connection: keep-alive
X-Powered-By: Express
Proof: close
ETag: "907060870"

hello%

How can I change keep-alive to close?

Versions

node 0.10.8
express 4.1.1

like image 318
Dean Avatar asked May 11 '14 08:05

Dean


1 Answers

It works fine for me. I test it localhost the same version.

$ curl -D - 127.0.0.1:3000
HTTP/1.1 200 OK
X-Powered-By: Express
Connection: close
Proof: close
Content-Type: text/html; charset=utf-8
Content-Length: 5
ETag: "907060870"
Date: Sun, 11 May 2014 08:52:32 GMT

hello%

I see that you may use nginx to proxy. Like below:

client--nginx proxy--real server

I guess that you should disable keep-alive in nginx config file.

like image 133
Tinple Avatar answered Oct 20 '22 00:10

Tinple