开发者

How can I redirect a HTTP POST request immediately after the headers are processed?

On Windows CE, I am currently in a situation where we implement a simplistic web server from scratch. The predominant use of this server will be in a one-to-one USB RNDIS connection. The server is hosted by the managed application running on the device.

Therefore, we tightly integrated POST request handling with delivered web pages. Instead of processing the complete request and storing POST data that would be too large, the current page (as identified by the request) is informed about any POSTed multipart by receiving its headers and a stream开发者_StackOverflow社区 of its contents. This solution works and shines and everybody is happy.

Now, here's the question: One page in the web interface of the application allows for uploading a software update, which can be 11 to, say, 40 MB in size. We have various validation steps in place while handling this POST request, like a permission system based on a session cookie. We know whether the client is allowed to upload a software update as soon as all headers are processed, due to said session cookie. Is there any way we can avoid having to read in (and discard) all of the POST content, so that users get immediate feedback?

Our first idea was to just return a proper error message response after header processing and then close the connection, but the browser (correctly, it seems) complained bitterly about a prematurely reset by the peer.


The browser is going to want that full transmission to happen. The way around it to give the user better responsiveness is probably to use an AJAX call on the page - so instead of the page receiving the data, the page should make an AJAX call to post the actual upload to another page asynchronously. Myself, I'd do this with jQuery, but you can put together the script without any framework to do it fairly easily.


Since I recently gave the relevant RFC a closer look:

HTTP 1.1 saw the inclusion of an additional request header for that kind of scenario

Expect: 100-Continue

This tells the Server to check the request headers and come back with either a "OK, you can now start sending me the actual content" or a "Sorry, whatever you intend to POST to me, I won't be able to deal with it" - response (for the more precise technicalities, see the HTTP 1.1 RFC)

However, this does not solve my scenario, since typical user agents (Firefox 3.6, IE 8) do not make use of this feature when POSTing multipart/form-data. A hand-grown helper applicaiton, however, might want to make use of this feature.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜