Node.js:在检索http请求主体之前断开http请求连接 [英] Node.js: Disconnect http request connection before the http request body has been retrieved
问题描述
我正在用Node.js编写一个http服务器。
I'm writing a http server with Node.js.
我有一个客户端通过HTTP POST(multipart / data)将一个大文件上传到这个服务器。
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.
我不知道如何断开http请求连接并返回正确的http响应。
I have no idea how to disconnect the http request connection and return the proper http response.
http请求只有req.pause()方法,这不是一个答案。
如果我调用req.connection.end(),则response.writeHeader()/ write()不会发送响应。
The http request has 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 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()
这篇关于Node.js:在检索http请求主体之前断开http请求连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!