Skip to content

Commit 8e8b214

Browse files
[[FEAT]] Add support for HTTPS
1 parent 6466795 commit 8e8b214

File tree

9 files changed

+3739
-11
lines changed

9 files changed

+3739
-11
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015-2016 Telefónica Investigación y Desarrollo, S.A.U
3+
Copyright (c) 2015-2018 Telefónica Investigación y Desarrollo, S.A.U
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![TypeScript definition](https://img.shields.io/badge/TypeScript%20Definition-%E2%9C%93-blue.svg)
44

5-
Allow terminating an HTTP server in an orderly fashion:
5+
Allow terminating an HTTP/HTTPS server in an orderly fashion:
66
* Immediately closes keep-alive connections that are not being used by any HTTP request.
77
* Waits for running HTTP requests to finish before closing their connections.
88
* Closes connections with running HTTP requests after a given timeout.

index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
The MIT License (MIT)
44
5-
Copyright (c) 2015-2016 Telefónica Investigación y Desarrollo, S.A.U
5+
Copyright (c) 2015-2018 Telefónica Investigación y Desarrollo, S.A.U
66
77
Permission is hereby granted, free of charge, to any person obtaining a copy
88
of this software and associated documentation files (the "Software"), to deal
@@ -55,19 +55,20 @@ function enableTerminate(server, opts) {
5555
});
5656

5757
server.on('request', function onRequest(req, res) {
58+
var connId = req.socket.id || req.socket._parent.id; // On SSL connections the TLS socket inherits from the original socket
5859
// Increase the number of running requests over the related connection
59-
connections[req.socket.id].runningRequests++;
60+
connections[connId].runningRequests++;
6061

6162
res.on('finish', function onFinish() {
6263
// Decrease the number of running requests over the related connection
6364
// (only if the socket has not been previously closed)
64-
if (connections[req.socket.id]) {
65-
connections[req.socket.id].runningRequests--;
65+
if (connections[connId]) {
66+
connections[connId].runningRequests--;
6667
// If this event happens after the "terminate" function has been invoked, it means that we are waiting
6768
// for running requests to finish, so close the connection as soon as the requests finish
68-
if (terminating && !connections[req.socket.id].runningRequests) {
69-
connections[req.socket.id].conn.destroy();
70-
delete connections[req.socket.id];
69+
if (terminating && !connections[connId].runningRequests) {
70+
connections[connId].conn.destroy();
71+
delete connections[connId];
7172
}
7273
}
7374
});

0 commit comments

Comments
 (0)