0

I have a lighttpd 1.4.35 running, and I need it to close the connection after every HTTP request. I'm expecting to see the "Connection:close" header in HTTP responses, but I don't. I receive something like this:

% curl -i http://192.168.12.1/files/                                                          

HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 1554
Date: Sat, 22 May 2021 16:29:05 GMT
Server: lighttpd/1.4.35

In order to have it send the "Connection: close" header, I added the following to the lighttpd.conf:

server.max-keep-alive-idle = 0
server.max-keep-alive-requests = 0
setenv.add-response-header = ( "connection" => "close" )

But I don't see any difference in the header. Am I missing something?

Note: the reason I am doing this is that in my setup (it's an embedded system), I can have only one TCP connection my lighttpd at a time, so I don't want a client to keep it alive and blocking other clients. Instead I want every client to close its TCP connection after every HTTP request, and for that I believe that my lighttpd should send Connection:close to inform e.g. Firefox to close the connection.

This is related to this and this questions.

JonasVautherin
  • 7,297
  • 6
  • 49
  • 95

2 Answers2

1

Have you tried the lighttpd documentation?

I can have only one TCP connection my lighttpd at a time, so I don't want a client to keep it alive

server.max-keep-alive-requests

server.max-connections

server.max-connections = 1
server.max-keep-alive-requests = 0

If you allowed more than one connection, then instead of disabling keep-alive, you might instead reduce the keep-alive idle time.

server.max-keep-alive-idle

server.max-keep-alive-idle = 1 will allow keep-alive, but if idle, will close the idle connection in 1-2 seconds.

BTW, lighttpd 1.4.35 is woefully out-of-date. lighttpd 1.4.35 was released in Mar 2014. Latest lighttpd release is lighttpd 1.4.63. Please consider upgrading.

gstrauss
  • 2,091
  • 1
  • 12
  • 16
  • Regarding the documentation, did you realize that 2 out of the three links you provide are already in my config file and in my question above? Unless I missed something, this does not work, and that's the reason for my question. For the server version, it's not my system, I don't have control over that. I wish I did, but I don't. – JonasVautherin Dec 21 '21 at 15:38
  • 1
    Manually adding hop-by-hop headers is almost always wrong, and I can't think of a situation where it would be ok. (Wrong: `setenv.add-response-header = ( "connection" => "close" )`). I overlooked your use of the other directives (sorry), but did provide links to the documentation for others who might read this. As for testing those directives with lighttpd 1.4.35, that version so grossly out-of-date that it is not worth anybody's time to troubleshooting it unless you're getting paid. Any OS distro version running that version of lighttpd is also grossly out-of-date and a security nightmare – gstrauss Dec 22 '21 at 16:27
0

I tried with a newer lighttpd (1.4.55) on my laptop, and my initial configuration with server.max-keep-alive-requests = 0 works there.

It seems like it doesn't work with 1.4.35 for some reason, so my solution is to get that updated.

JonasVautherin
  • 7,297
  • 6
  • 49
  • 95