Skip to content

HTTP client strange behavior when server responds immediately without reading request body #9085

@ghost

Description

In the example below an HTTP server doesn't read the the request body, but returns the response immediately. If the client sends large data (e.g. 10,000,000 bytes) ECONNRESET error is emitted at client-side but on small data (e.g. 1,000,000 bytes) the programs runs silently.

var crypto = require('crypto'),
    http = require('http')

var port = 8080

var server = http.createServer((req, res) => {
    res.end(crypto.randomBytes(10000))
})
server.listen(port, () => {
    var req = http.request({
        port: port,
        method: 'post',
    })
    req.end(crypto.randomBytes(10000000)) // <- play this value, remove zeros, then add
})

I think the client still sends data after receiving the response. Thus the client violates HTTP request syntax and the connection gets reset. Is this the expected behavior? If so what's the correct way of handling this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    httpIssues or PRs related to the http subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions