nodejs / node-v0.x-archive

Moved to https://github.com/nodejs/node
34.42k stars 7.31k forks source link

http parser problem in V 0.8.14 #4394

Closed kaoshijuan closed 11 years ago

kaoshijuan commented 11 years ago

i created an http client to get the URL http://www.simsimi.com/func/req?msg=test&lc=ch , and the response made the node got an error HPE_INVALID_HEADER_TOKEN, i'm wondering there is something wrong with the parser of the http protocol.

it's OK while I use the browser like IE or chrome, and it also works well while using Python 2.7.3 to access this URL.

bnoordhuis commented 11 years ago

The server returns an invalid response.

$ curl -v 'http://www.simsimi.com/func/req?msg=test&lc=ch'
* About to connect() to www.simsimi.com port 80 (#0)
*   Trying 50.16.220.34... connected
> GET /func/req?msg=test&lc=ch HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: www.simsimi.com
> Accept: */*
> 
< HTTP/1.1 200 OK
< Cache-Control: no-cache
< Content-Language: en
< Content-Type: text/html;charset=UTF-8
< Date: Mon, 10 Dec 2012 09:36:43 GMT
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Pragma: no-cache
< Server: Apache-Coyote/1.1
< Set-Cookie: JSESSIONID=095D7ED1038F217E6148B3321F6821B2; Path=/; HttpOnly
< text/html: utf-8
< Content-Length: 55
< Connection: keep-alive
< 
* Connection #0 to host www.simsimi.com left intact
* Closing connection #0
{"response":"hi","id":1466090,"result":100,"msg":"OK."}

Note the line that says text/html: utf-8. The HTTP parser in node.js is unforgiving of such spec violations.

kaoshijuan commented 11 years ago

I think the parser should be more robust and it can tolerate the violations.

indutny commented 11 years ago

For what reason? Also you can always use raw net interface and implement your own http client on top of it.

Parser is intolerant exactly for robustness and performance reasons.