Do you have a repeatable test case? (By the way, top-posting is a mortal sin).
I suspect your request body has a trailing CRLF. Your example works if
I bump the Content-Length to 8.
$ nc -Cv4 127.0.0.1 8001
Connection to 127.0.0.1 8001 port [tcp/*] succeeded!
POST /post HTTP/1.1
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Content-Length: 8
Connection: close
Host: localhost
Sample
HTTP/1.1 200 OK
Content-Type: text/plain
Connection: close
Transfer-Encoding: chunked
c
Hello World
0
> I have three files. (1) a copy of the request from PHP with the extra
> CR LF CR LF at the end (seen above), (2) the request with the last 4
> characters removed, and (3) a GET request that looks great. 2 and 3
> both will get a response from the server. Why is the response from 1
> not working?
>
> 16:34 clove:~/node_bug$ nc -v -q 10 localhost 8001 < request.dump
> Connection to localhost 8001 port [tcp/*] succeeded!
> 16:34 clove:~/node_bug$
Note that `nc` is tricky in that it won't print to stdout if stdin
isn't a tty. I've no idea why it does that - it's annoying.
> Is the HTTP module reading more from the request and deciding it is
> invalid? I don't disagree with that behavior, but it looks like it
> closes the socket before the response for the first request is
> served. If I pegged that correctly, shouldn't the first request get
> fully processed before the second one is started? I wouldn't want
> previous requests to get abandoned because the following request is
> formatted poorly.
On Tue, Jun 7, 2011 at 23:50, fidian <minimif...@gmail.com> wrote:
> Wow, the hex dump of my file got mangled. I can put the files up on
> the web if you want to download them.
Yes, please. It's rather hard to parse this way. If request #1 is okay
and request #2 is malformed, #1 should still be served.
> The other thing I forgot to mention was that if you remove the
> "Connection: close" header, everything works fine even though it has
> the extra CR/LF CR/LF at the end. Why would the socket get closed
> early with the "Connection: close" header and not closed early without
> it?
Because the HTTP parser thinks that the extraneous junk is the
beginning of a new request (if "Connection: close" isn't set).
Trailing CRLFs are fairly common, it seems, so the parser has a
special case built in that deals with them.
Maybe it's the version of `nc` that ships with Ubuntu Lucid.
> I have put my files on the net: http://rumkin.com/media/support_files.tar.gz
>
> I've filed an official "issue" on github for this problem. It has
> some more information about where I think the problem lies, but I'm
> still really new to this. https://github.com/joyent/node/issues/1165
Using this[1] and this[2] and the example requests from your tarball,
I get back this:
$ cat tmp/request.noclose tmp/request.nocrlf | ./netcat.py localhost 8001
POST /post HTTP/1.1
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Content-Length: 6
Host: localhost
Sample
POST /post HTTP/1.1
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Content-Length: 6
Connection: close
Host: localhost
SampleHTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 12
Connection: keep-alive
Hello World
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 12
Connection: close
Hello World
Here is what server.js logs:
Request { 'content-type': 'application/x-www-form-urlencoded;
charset=utf-8',
'content-length': '6',
host: 'localhost' }
Received chunk <Buffer 53 61 6d 70 6c 65> Sample
Request { 'content-type': 'application/x-www-form-urlencoded;
charset=utf-8',
'content-length': '6',
connection: 'close',
host: 'localhost' }
Received chunk <Buffer 53 61 6d 70 6c 65> Sample
About what you would expect, right? This is with the master branch,
commit 7a5977b (June 7).
[1] https://gist.github.com/1015643 (netcat.py)
[2] https://gist.github.com/1015649 (server.js)