Skip to content

Sending response before request is fully read #206

@JRoush

Description

@JRoush

I'm having a problem sending prompt responses to large requests.

As of v0.8.2, Request::respond() will wait until "Content-Length" bytes have been received from the client before sending the response. I would prefer to send the response immediately. For example, if the request claims a content length of 100GB, I would like to send "413 Payload too Large" without waiting for the whole request body to arrive.

Note that responses are sent promptly to requests with "Transfer-Encoding: chunked" or "Expect: 100 continue". This doesn't help me because I am handling XHR, and web browsers do not allow control of either of these headers on XHR for security reasons. In any case, I think it would be better if tiny_http could send prompt responses regardless of how the request is structured.

The current behavior was introduced in commit 091ce80. The motivation for that commit seems reasonable, but I believe that the server author should decide whether a request should be fully read before sending the response.

I have written some test code that reflects what I think would be the "correct" behavior of the library. It can be dropped in the "tests/" directory and run via cargo test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions