@@ -110,6 +110,7 @@ export class NodeHttpRequestResponseHandler implements NodeHttpStreamsHandler {
110110
111111 if ( ! nodeHttpStreams . requestStream ) {
112112
113+ // No request was received, this path is technically impossible to reach
113114 this . logger . error ( 'No request stream received' , { nodeHttpStreams } ) ;
114115
115116 return throwError ( ( ) => new Error ( 'request stream cannot be null or undefined.' ) ) ;
@@ -118,6 +119,7 @@ export class NodeHttpRequestResponseHandler implements NodeHttpStreamsHandler {
118119
119120 if ( ! nodeHttpStreams . requestStream . headers ) {
120121
122+ // No request headers were received, this path is technically impossible to reach
121123 this . logger . error ( 'No request headers received' , { requestStream : nodeHttpStreams . requestStream } ) ;
122124
123125 return throwError ( ( ) => new Error ( 'headers of the request cannot be null or undefined.' ) ) ;
@@ -138,6 +140,7 @@ export class NodeHttpRequestResponseHandler implements NodeHttpStreamsHandler {
138140
139141 if ( ! nodeHttpStreams . responseStream ) {
140142
143+ // No response was received, this path is technically impossible to reach
141144 this . logger . error ( 'No response stream received' , { nodeHttpStreams } ) ;
142145
143146 return throwError ( ( ) => new Error ( 'response stream cannot be null or undefined.' ) ) ;
@@ -148,19 +151,36 @@ export class NodeHttpRequestResponseHandler implements NodeHttpStreamsHandler {
148151
149152 if ( ! url ) {
150153
154+ // No request url was received, this path is technically impossible to reach
151155 this . logger . warn ( 'No url received' , { requestStream : nodeHttpStreams . requestStream } ) ;
152156
153157 return throwError ( ( ) => new Error ( 'url of the request cannot be null or undefined.' ) ) ;
154158
155159 }
156160
161+ // Check if the request method is an HTTP method + this ensures typing throughout the file
157162 const method = Object . values ( HttpMethods ) . find ( ( m ) => m === nodeHttpStreams . requestStream . method ) ;
158163
159164 if ( ! method ) {
160165
161- this . logger . warn ( 'No method received' , { requestStream : nodeHttpStreams . requestStream } ) ;
166+ if ( nodeHttpStreams . requestStream . method ) {
162167
163- return throwError ( ( ) => new Error ( 'method of the request cannot be null or undefined.' ) ) ;
168+ // An unsupported method was received
169+ this . logger . warn ( 'Invalid method received' , { method : nodeHttpStreams . requestStream . method } ) ;
170+ this . logger . clearVariables ( ) ;
171+ nodeHttpStreams . responseStream . writeHead ( 405 , 'Only HTTP methods are allowed!' ) ;
172+ nodeHttpStreams . responseStream . end ( ) ;
173+
174+ return of ( void 0 ) ;
175+
176+ } else {
177+
178+ // No request method was received, this path is technically impossible to reach
179+ this . logger . warn ( 'No method received' , { requestStream : nodeHttpStreams . requestStream } ) ;
180+
181+ return throwError ( ( ) => new Error ( 'method of the request cannot be null or undefined.' ) ) ;
182+
183+ }
164184
165185 }
166186
0 commit comments