开发者

Node.js: Disconnect http request connection before the http request body has been retrieved

I'm writing a http server with Node.js.

I have a client to upload a large file to this server via HTTP POST(multipart/data).

I want to accept the only connection which upload the file with valid filename.(I have some conditions.) The invalid filename connection should be disconnected before the server retrieves the data.

I have no idea how to disconnect the http request connection and return the proper http response.

The http request ha开发者_运维知识库s only req.pause() method which isn't an answer. and if I call req.connection.end(), the response.writeHeader()/write() doesn't send the response.


I think you'll need to send a response.end() to send your writeHeader()/write() calls, followed by a req.connection.end() to end the request without receiving any further data.


I would have thought the following should work since the request and response objects share the same socket... but it seems unreliable. Maybe it's a bug in node?

request.connection.allowHalfOpen = false
response.writeHead 500, 
    'Access-Control-Allow-Origin' : '*'
response.end()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜