uNetworking / uWebSockets

Simple, secure & standards compliant web server for the most demanding of applications
Apache License 2.0
17.29k stars 1.75k forks source link

v20.12.0 upload large files failed #1538

Closed zdm closed 11 months ago

zdm commented 1 year ago

Upload large files impossible when content-length is present, With chunked encoding works file.

import uws from "uWebSockets.js";

uws.App()
    .post( "/*", post )
    .listen( 80, () => {} );

async function post ( res, req ) {
    res.onAborted( () => {
        console.log( "--- ABORTED" );
    } );

    res.onData( ( arrayBuffer, isLast ) => {
        console.log( "---", isLast, arrayBuffer.byteLength );
    } );
}

Test

Tested on Windows and Linux, nodejs 18.

test.mkv shpuld be really large, 18 Gb in my case.

Non-chunked:

curl -X post -T test.mkv http://127.0.0.1/ -v

*   Trying 127.0.0.1:80...
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> post /test.mkv HTTP/1.1
> Host: 127.0.0.1
> User-Agent: curl/7.83.1
> Accept: */*
> Content-Length: 20036037246
> Expect: 100-continue
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 100 Continue
* Recv failure: Connection was reset
* Closing connection 0
curl: (56) Recv failure: Connection was reset

Upload failed, socket dropped.

Chunked:

curl -X post -T test.mkv -H "Transfer-Encoding: chunked" http://127.0.0.1/ -v

*   Trying 127.0.0.1:80...
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> post /test.mkv HTTP/1.1
> Host: 127.0.0.1
> User-Agent: curl/7.83.1
> Accept: */*
> Transfer-Encoding: chunked
> Expect: 100-continue
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 100 Continue
* Signaling end of chunked upload via terminating chunk.
^C

Upload done.

uNetworkingAB commented 1 year ago

Maximum content length is 1gb. Might need to bump it a bit

zdm commented 11 months ago

not actual