loopbackio / strong-soap

SOAP driver for Node.js (A complete rewrite of node-soap)
Other
390 stars 159 forks source link

The service crashes if content-type and body are undefined #375

Closed francois-spectre closed 2 years ago

francois-spectre commented 2 years ago

The issue

If I do a curl to the strong-api route without headers neither body an issue is thrown and is not caught anywhere Invalid value "undefined" for header "Content-Type"

I would expect the server to return a 400 "Bad request", or ignore it, or run a default "controller", or anything but not crashing the server. What can I do to solve this issue?

Error detail

node:_http_outgoing:566
    throw new ERR_HTTP_INVALID_HEADER_VALUE(value, name);
    ^

TypeError: Invalid value "undefined" for header "Content-Type"
    at ServerResponse.setHeader (node:_http_outgoing:579:3)
    at Server._requestListener (/Users/francois-spectre/Workspace/vauxhall/node_modules/strong-soap/src/server.js:84:11)
    at Server.<anonymous> (/Users/francois-spectre/Workspace/vauxhall/node_modules/strong-soap/src/server.js:54:16)
    at Server.emit (node:events:390:28)
    at Server.emit (node:domain:475:12)
    at parserOnIncoming (node:_http_server:951:12)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17) {
  code: 'ERR_HTTP_INVALID_HEADER_VALUE'
}
[nodemon] app crashed - waiting for file changes before starting...

It happens here in the code: https://github.com/loopbackio/strong-soap/blob/86c86a109b4fe8af85d4f67b195a3c877e351e51/src/server.js#L84

francois-spectre commented 2 years ago

@achrinza I could fix it but which behaviour would you like? We could return a 400 "Bad request" or use a default Content-Type value for instance...

dhmlau commented 2 years ago

@francois-spectre, what about 415? https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/415. Would you be interested to submit a PR?

francois-spectre commented 2 years ago

@dhmlau I have implemented the 415 error ^