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

HTTP parse error on request using a non standard method #2775

Closed
pbuyle opened this issue Feb 17, 2012 · 7 comments
Closed

HTTP parse error on request using a non standard method #2775

pbuyle opened this issue Feb 17, 2012 · 7 comments
Labels

Comments

@pbuyle
Copy link

pbuyle commented Feb 17, 2012

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).

@pbuyle pbuyle closed this as completed Feb 17, 2012
@pbuyle
Copy link
Author

pbuyle commented Feb 17, 2012

This seems to be a bug/limitation of http_parser and has been reported there (cf. nodejs/http-parser#92)

@bnoordhuis
Copy link
Member

Reopening this for now, nodejs/http-parser#93 adds PURGE support to http_parser.c but it needs updated bindings in node_http_parser.cc.

EDIT: Updated in bnoordhuis/node@9986989.

@izuzak
Copy link

izuzak commented Feb 18, 2012

Hi @bnoordhuis - while that does solve the immediate problem, what's your take on the generic issue at hand - allowing any non-standard HTTP method?

I agree with @pbuyle that at least a 501 response should be sent on non-supported methods, while it would be better either to support any non-standard method to be parsed or to allow the set of methods recognized by the parser to be configured at runtime.

@bnoordhuis
Copy link
Member

Hi @bnoordhuis - while that does solve the immediate problem, what's your take on the generic issue at hand - allowing any non-standard HTTP method?

It's been discussed a couple of times but nothing really came of it. I would accept a patch that doesn't impose a speed or memory penalty.

bnoordhuis added a commit to nodejs/http-parser that referenced this issue Feb 20, 2012
@bnoordhuis
Copy link
Member

PURGE support landed in f0c5165 and de5e3f6. Thanks for the report.

@pbuyle
Copy link
Author

pbuyle commented Apr 16, 2012

Any chance of seeing this releases in a 0.6.x release?

@bnoordhuis
Copy link
Member

The delta between master and v0.6 is pretty big by now, both for node and http-parser, so it's not trivial to back-port. I'll consider pull requests though, go ahead if you want to have a stab at it.

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

Successfully merging a pull request may close this issue.

3 participants