Skip to content
This repository was archived by the owner on Jul 6, 2018. It is now read-only.
This repository was archived by the owner on Jul 6, 2018. It is now read-only.

http2 client: end event not emitted if no data listener registered #99

Closed

Description

@robertkowalski

The http2 client will not emit end, given no data listener is registered, even if the server ends the response.

The following code calls req.on('end') just in the case req.on('data') is registered.

'use strict';
require('../common');
const assert = require('assert');
const http2 = require('http2');

const testResBody = 'other stuff!\n';

const server = http2.createServer((req, res) => {
  res.writeHead(200, {
    'Content-Type': 'text/plain'
  });
  res.end(testResBody);
});

server.listen(0, function() {
  const client = http2.connect(`http://localhost:${this.address().port}`);

  const headers = { ':path': '/' };
  const req = client.request(headers)
  req.setEncoding('utf8');

  // XXX: remove this and ` req.on('end')` is never called 
  let data = '';
  req.on('data', (d) => data += d);

  req.on('response', (headers) => {
    assert.ok('date' in headers,
              'Response headers contain a date.');
  });

  req.on('end', () => {
    server.close();
    process.exit();
  });
  req.end();
});

Activity

  1. mcollina commented on May 15, 2017

    @mcollina
    SponsorMember

    This is expected, as 'end'  does not trigger the stream to flow. You should manually call resume(), add a on('data') or on('readable') event. This is part of streams, not http2.

  2. robertkowalski commented on May 15, 2017

    @robertkowalski
    ContributorAuthor
  3. mcollina commented on May 15, 2017

    @mcollina
    SponsorMember

    Have a look at:

  4. robertkowalski commented on May 15, 2017

    @robertkowalski
    ContributorAuthor

    doh!

    man thank you, I got a bit rusty!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions