File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -152,5 +152,24 @@ module.exports = function(server, opts) {
152152 } ) ;
153153 }
154154
155+ primus . transformer . on ( 'previous::upgrade' , function ( req , socket , head ) {
156+ abortConnection ( socket , 404 , 'Not Found' ) ;
157+ } ) ;
158+
155159 return require ( './manager' ) ( primus , opts ) ;
156160} ;
161+
162+ function abortConnection ( socket , code , name ) {
163+ try {
164+ var response = [
165+ 'HTTP/1.1 ' + code + ' ' + name ,
166+ 'Content-type: text/html'
167+ ] ;
168+ socket . write ( response . concat ( '' , '' ) . join ( '\r\n' ) ) ;
169+ }
170+ catch ( e ) { /* ignore errors - we've aborted this connection */ }
171+ finally {
172+ // ensure that an early aborted connection is shut down completely
173+ try { socket . destroy ( ) ; } catch ( e ) { }
174+ }
175+ }
You can’t perform that action at this time.
0 commit comments