witheve / Eve

Better tools for thought

Home Page:http://witheve.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Server crashes on HTTP response without Content-Type header

JulianKniephoff opened this issue · comments

I am running Eve in --server mode and running the following snippet:

commit @http
  [#request url: "http://localhost:8081"]

from within the editor, where http://localhost:8081 is running a minimal Node.js server:

require('http').createServer((request, response) => {
	response.end('Hello, World!\n');
}).listen(8081);

This crashes the Eve server with the following backtrace:

/Users/jules/src/Eve/build/src/runtime/server.js:301
            throw err;
            ^

TypeError: Cannot read property 'indexOf' of undefined
    at Request._callback (/Users/jules/src/Eve/build/src/runtime/databases/node/http.js:56:49)
    at Request.self.callback (/Users/jules/src/Eve/node_modules/request/request.js:186:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:192:7)
    at Request.<anonymous> (/Users/jules/src/Eve/node_modules/request/request.js:1081:10)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:189:7)
    at IncomingMessage.<anonymous> (/Users/jules/src/Eve/node_modules/request/request.js:1001:12)
    at Object.onceWrapper (events.js:291:19)
    at emitNone (events.js:91:20)

The line that this fails in is the following this:

      if(response.headers["content-type"].indexOf("application/json") > -1) {

When the response is lacking the Content-Type header like in the example above, this crashes because then response.headers['content-type'] is undefined.

I know the snippet above might not be the most useful server, but as far as I know, the Content-Type header is not mandatory, so this should probably not happen.

I tested this with the master on macOS 10.12.3.