Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse error #37

Closed
creeperyang opened this issue Jan 3, 2016 · 3 comments
Closed

Parse error #37

creeperyang opened this issue Jan 3, 2016 · 3 comments
Assignees

Comments

@creeperyang
Copy link

I want to test the length option but get Parse Error instead of the expected 400 error code. The lib cant capture the error and just throw it out.

rawBody(request, { limit: '1mb', encoding: 'utf8', length: 191 })

// the request:

request(app.listen())
    .post('/')
    .set('Content-Type', 'text/xml')
    .set('Content-Length', 191) // here is the length 
    .send(sourceXml) // the data's actual length is 197
    .expect(200, done);

and I get the error:

Error: Parse Error
      at Error (native)
      at Socket.socketOnData (_http_server.js:343:22)
      at Socket.emit (events.js:107:17)
      at readableAddChunk (_stream_readable.js:163:16)
      at Socket.Readable.push (_stream_readable.js:126:10)
      at TCP.onread (net.js:538:20)
@dougwilson dougwilson self-assigned this Jan 4, 2016
@dougwilson
Copy link
Member

Hi! I'll take a look into it, but for the cases where the length is longer than Content-Length and you are handling that in a Node.js code HTTP server, the Parse Error is probably too low for us to have any information that will be useful for you.

While I'm taking a look, please feel free to see if you can propose a pull request with a fix in the meantime as well!

@creeperyang
Copy link
Author

Thanks for reply. I looked through the code and set some breakpoint, and I found maybe it's really too low to capture the error or control the handling flow.

@dougwilson
Copy link
Member

So, I took a hard look into this just now, and I was not able to get the issue to be captured by this module. The provided error will pretty much always occur outside the scope of a request or response object, instead the parse error occurs on the socket. This module should raise a request aborted internally, but Node.js will destroy the socket on a parse error, so you wouldn't be able to respond with any HTTP response anyhow :/

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

No branches or pull requests

2 participants