Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

http: createServer request.method is null for DELETE requests #6461

Closed
SaltwaterC opened this issue Nov 4, 2013 · 5 comments
Closed

http: createServer request.method is null for DELETE requests #6461

SaltwaterC opened this issue Nov 4, 2013 · 5 comments
Assignees

Comments

@SaltwaterC
Copy link

The issue appeared in node.js v0.11.8.

Proof of concept server:

var http = require('http')

http.createServer(function (req, res) {
    res.writeHead(200, {
        'x-http-method': req.method
    })
    res.end()
}).listen(3000)

Trigger the issue on faulty versions:

~ curl -X GET -i localhost:3000
HTTP/1.1 200 OK
x-http-method: GET
Date: Mon, 04 Nov 2013 16:43:08 GMT
Connection: keep-alive
Transfer-Encoding: chunked

~ curl -X DELETE -i localhost:3000
HTTP/1.1 200 OK
x-http-method: null
Date: Mon, 04 Nov 2013 16:43:10 GMT
Connection: keep-alive
Transfer-Encoding: chunked

Quite needless to say that it is present in the master branch.

@craigminihan
Copy link

I guess this issue in Express 3.3.4 against 0.11.8 is related:

var app = express();
app.delete('/:db/:id', api.delete);

When delete is called we get a stack dump as follows:

TypeError: Cannot call method 'toLowerCase' of null
    at Router.matchRequest (...\node_modules\express\lib\router\index.js:223:27)
    at pass (...\node_modules\express\lib\router\index.js:104:30)
    at Router._dispatch (...\node_modules\express\lib\router\index.js:173:5)
    at Object.router (...\node_modules\express\lib\router\index.js:33:10)
    at next (...\node_modules\express\node_modules\connect\lib\proto.js:193:15)
    at next (...\node_modules\express\node_modules\connect\lib\proto.js:168:78)
    at Object.json [as handle] (...\node_modules\express\node_modules\connect\lib\middleware\json.js:51:37)
    at next (...\node_modules\express\node_modules\connect\lib\proto.js:193:15)
    at Object.compress [as handle] (...\node_modules\express\node_modules\connect\lib\middleware\compress.js:182:5)
    at next (...\node_modules\express\node_modules\connect\lib\proto.js:193:15)

The problem only seems to affect delete against the express app object. The other HTTP handling methods work fine.
This worked fine in 0.11.6.

@TooTallNate
Copy link

If I were to guess, I'd say probably related to 4c0195e.

@TooTallNate
Copy link

This seems to do it for me. The problem is that DELETE is at index 0, so the if check is, well, too aggressive. I'll try to whip up a proper commit+test case for this in a little bit.

diff --git a/lib/_http_common.js b/lib/_http_common.js
index 2fb5bd8..7d89b86 100644
--- a/lib/_http_common.js
+++ b/lib/_http_common.js
@@ -27,6 +27,7 @@ var IncomingMessage = incoming.IncomingMessage;
 var readStart = incoming.readStart;
 var readStop = incoming.readStop;

+var isNumber = require('util').isNumber;
 var debug = require('util').debuglog('http');
 exports.debug = debug;

@@ -90,7 +91,7 @@ function parserOnHeadersComplete(info) {

   parser.incoming._addHeaderLines(headers, n);

-  if (info.method) {
+  if (isNumber(info.method)) {
     // server only
     parser.incoming.method = HTTPParser.methods[info.method];
   } else {

@TooTallNate
Copy link

@ghost ghost assigned TooTallNate Nov 4, 2013
@TooTallNate
Copy link

Fixed in 9bc53d8. @SaltwaterC thanks for the report!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants