Skip to content

HTTP IncomingMessage (response) complete property is false #1493

@kadler15

Description

@kadler15

Not sure how much of this is mocked as part of this library, but I noticed that the complete property on the response to a http request remains false, even after the entire reply message is received by the client (data and end events handled). E.g.:

nock('http://test.com')
  .replyDate()
  .defaultReplyHeaders({
    'Content-Type': 'application/text',
    'Content-Length': function(req, res, body) { return body.length; },
  })
  .get('/testFile.txt')
  .reply(200, Buffer.from(new Array(10000).fill('a')));
http.request({
  method: 'GET',
  url: 'http://test.com/testFile.txt'
  host: 'test.com',
  path: '/testFile.txt'
}, function(response) {
  const data = []
  response.on('data', function(chunk) { data.push(chunk); });
  response.on('end', function() {
    if (!response.complete) {
      console.log('Connection terminated while the message was being sent');  // <-- The case with nock
    } else {
      console.log('Entire message received');
    }
  });
});

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions