-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: add drop request event for http server
PR-URL: #43806 Reviewed-By: Matteo Collina <[email protected]>
- Loading branch information
1 parent
ef21ad2
commit ca658c8
Showing
4 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const http = require('http'); | ||
const net = require('net'); | ||
const assert = require('assert'); | ||
|
||
function request(socket) { | ||
socket.write('GET / HTTP/1.1\r\n'); | ||
socket.write('Connection: keep-alive\r\n'); | ||
socket.write('\r\n\r\n'); | ||
} | ||
|
||
const server = http.createServer(common.mustCall((req, res) => { | ||
res.end('ok'); | ||
})); | ||
|
||
server.on('dropRequest', common.mustCall((request, socket) => { | ||
assert.strictEqual(request instanceof http.IncomingMessage, true); | ||
assert.strictEqual(socket instanceof net.Socket, true); | ||
server.close(); | ||
})); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const socket = net.connect(server.address().port); | ||
socket.on('connect', common.mustCall(() => { | ||
request(socket); | ||
request(socket); | ||
})); | ||
socket.on('data', common.mustCallAtLeast()); | ||
socket.on('close', common.mustCall()); | ||
})); | ||
|
||
server.maxRequestsPerSocket = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const https = require('https'); | ||
const http = require('http'); | ||
const net = require('net'); | ||
const assert = require('assert'); | ||
const tls = require('tls'); | ||
const { readKey } = require('../common/fixtures'); | ||
|
||
function request(socket) { | ||
socket.write('GET / HTTP/1.1\r\nConnection: keep-alive\r\n\r\n\r\n'); | ||
} | ||
|
||
// https options | ||
const httpsOptions = { | ||
key: readKey('agent1-key.pem'), | ||
cert: readKey('agent1-cert.pem') | ||
}; | ||
|
||
const server = https.createServer(httpsOptions, common.mustCall((req, res) => { | ||
res.end('ok'); | ||
})); | ||
|
||
server.on('dropRequest', common.mustCall((request, socket) => { | ||
assert.strictEqual(request instanceof http.IncomingMessage, true); | ||
assert.strictEqual(socket instanceof net.Socket, true); | ||
server.close(); | ||
})); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const socket = tls.connect( | ||
server.address().port, | ||
{ | ||
rejectUnauthorized: false | ||
}, | ||
common.mustCall(() => { | ||
request(socket); | ||
request(socket); | ||
socket.on('error', common.mustNotCall()); | ||
socket.on('data', common.mustCallAtLeast()); | ||
socket.on('close', common.mustCall()); | ||
}) | ||
); | ||
})); | ||
|
||
server.maxRequestsPerSocket = 1; |