joyent/node — Issue #2775: HTTP parse error on request using a non standard method
Author: pbuyle
Created: 2012-02-17 20:28:27+00:00
State: open

I'm trying to serve PURGE request from a HTTP server implemented using Node.JS. PURGE requests are used by Squid and Varnish to purge objects from their cache (cf. http://wiki.squid-cache.org/SquidFaq/OperatingSquid#How_can_I_purge_an_object_from_my_cache.3F and https://www.varnish-cache.org/docs/trunk/tutorial/purging.html).

But Node.JS's HTTP server does let not my code serve non-standard HTTP method. Instead, when receiving a request line using a non-standard method, the server close the connection after a parser error.

Server code and output:
```
$ node
> require('http').createServer(function(req, res) {
... console.log(req.method);
... res.end();
... }).listen(8080);
{ connections: 0,
allowHalfOpen: true,
_handle:
{ writeQueueSize: 0,
onconnection: [Function: onconnection],
socket: [Circular] },
_events:
{ request: [Function],
connection: [Function: connectionListener] },
httpAllowHalfOpen: false }
> HTTP: SERVER new http connection
HTTP: parse error
HTTP: server socket close
```
Client command:
```
$ telnet localhost 8080
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
PURGE / HTTP/1.1
Connection closed by foreign host.
```

According to the HTTP 1.1 specification (rfc2616, section 5.1), the method of a request line can be any valid token, so it seems natural to expect an HTTP server to accept any method in the request line and answer with an error 501 (Not Implemented).