Working on peer authentication, using the zetta-peer-auth as a starting point. We’re using the ‘onPeerConnect’ hook, but aren’t sure exactly what the handler function should do if credentials are not accepted. Here’s what we got so far:
server.httpServer.onPeerConnect(function(message, socket, head, next) {
if (!credentialsPass(message.headers.authorization)) {
var responseLine = 'HTTP/1.1 401 Unauthorized' + '\r\n\r\n\r\n';
socket.write(responseLine);
message.destroy();
}
next();
});
This does not clean things up properly, since it leaves the peer_socket to just timeout.
What’s the proper way for the handler to respond and close the connection?