Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken with Node.js 14.0.0 #39

Closed
masx200 opened this issue Apr 25, 2020 · 4 comments
Closed

Broken with Node.js 14.0.0 #39

masx200 opened this issue Apr 25, 2020 · 4 comments

Comments

@masx200
Copy link

masx200 commented Apr 25, 2020

 node -v
v14.0.0

package.json

{
  "name": "temp",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "http2-wrapper": "^1.0.0-beta.4.4"
  }
}

Use http2-wrapper to send the request.After that, there is no response and the nodejs program exits directly.

const http2 = require("http2-wrapper");

const options = {
    hostname: "translate.google.cn",
    protocol: "https:", // Note the `http:` protocol here
    path: "/",
    method: "GET",
    headers: {},
};
(async () => {
    try {
        const request = await http2.auto(options, (response) => {
            console.log("statusCode:", response.statusCode);
            console.log("headers:", response.headers);

            const body = [];
            response.on("data", (chunk) => body.push(chunk));
            response.on("end", () => {
                console.log("body:\n", Buffer.concat(body).toString());
            });
        });
        console.log(request);
        request.on("error", console.error);

        request.end();
    } catch (error) {
        console.error(error);
    }
})();

Use the native http2 module as follows. Successful response.

const http2 = require("http2");

const {
    HTTP2_HEADER_STATUS,
    HTTP2_HEADER_PATH,
    HTTP2_HEADER_METHOD,
} = http2.constants;
const client = http2.connect("https://translate.google.cn", {});
client.on("error", (err) => console.error(err));

const req = client.request({
    [HTTP2_HEADER_PATH]: "/",
    [HTTP2_HEADER_METHOD]: "GET",
});
console.log(req);
req.on("response", (headers, flags) => {
    console.log("statusCode:", headers[HTTP2_HEADER_STATUS]);
    console.log("headers:", headers);
});

req.setEncoding("utf8");
let data = "";
req.on("data", (chunk) => {
    data += chunk;
});
req.on("end", () => {
    console.log(`body:\n${data}`);
    client.close();
});
req.end();
Http2Stream {
  id: '<pending>',
  closed: false,
  destroyed: false,
  state: {},
  readableState: ReadableState {
    objectMode: false,
    highWaterMark: 16384,
    buffer: BufferList { head: null, tail: null, length: 0 },
    length: 0,
    pipes: [],
    flowing: null,
    ended: false,
    endEmitted: false,
    reading: false,
    sync: true,
    needReadable: false,
    emittedReadable: false,
    readableListening: false,
    resumeScheduled: false,
    errorEmitted: false,
    emitClose: true,
    autoDestroy: false,
    destroyed: false,
    errored: false,
    closed: false,
    defaultEncoding: 'utf8',
    awaitDrainWriters: null,
    multiAwaitDrain: false,
    readingMore: true,
    decoder: null,
    encoding: null,
    [Symbol(kPaused)]: null
  },
  writableState: WritableState {
    objectMode: false,
    highWaterMark: 16384,
    finalCalled: true,
    needDrain: false,
    ending: true,
    ended: true,
    finished: false,
    destroyed: false,
    decodeStrings: false,
    defaultEncoding: 'utf8',
    length: 0,
    writing: false,
    corked: 0,
    sync: true,
    bufferProcessing: false,
    onwrite: [Function: bound onwrite],
    writecb: null,
    writelen: 0,
    afterWriteTickInfo: null,
    bufferedRequest: null,
    lastBufferedRequest: null,
    pendingcb: 1,
    prefinished: false,
    errorEmitted: false,
    emitClose: true,
    autoDestroy: false,
    errored: false,
    closed: false,
    bufferedRequestCount: 0,
    corkedRequestsFree: {
      next: null,
      entry: null,
      finish: [Function: bound onCorkedFinish]
    }
  }
}
statusCode: 200
headers: [Object: null prototype] {
  ':status': 200,
  date: 'Sat, 25 Apr 2020 01:52:08 GMT',
  pragma: 'no-cache',
  expires: 'Fri, 01 Jan 1990 00:00:00 GMT',
  'cache-control': 'no-cache, must-revalidate',
  'x-frame-options': 'DENY',
  'content-type': 'text/html; charset=GB2312',
  'content-language': 'zh-CN',
  p3p: 'CP="This is not a P3P policy! See g.co/p3phelp for more info."',
  'x-content-type-options': 'nosniff',
  server: 'HTTP server (unknown)',
  'x-xss-protection': '0',
  'set-cookie': [
    'NID=203=NUm7GCDy0VPapvOEizE7Pt62uYET8mFwLWNM227xdaILpjliZaKQmEDchyBbrxVLZ0fIbKEBNUOcfXKuYmhrsHcl7mY2TCHD5koo83FgCSGfYqneog86gQtmmL9N9YBcMx8CeV2uMaU5SlpXKduR_O2aArx62n1uLlu9N21nkQ0; expires=Sun, 25-Oct-2020 01:52:08 GMT; path=/; domain=.google.cn; HttpOnly'
  ],
  'alt-svc': 'quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,h3-T050=":443"; ma=2592000',
  'accept-ranges': 'none',
  vary: 'Accept-Encoding'
}
body:
@masx200 masx200 changed the title Failed to send http2 request. No response received. Failed to send http2 request or No response received. Apr 25, 2020
@szmarczak szmarczak changed the title Failed to send http2 request or No response received. Broken with Node.js 14.0.0 Apr 25, 2020
@szmarczak
Copy link
Owner

Related with sindresorhus/got#1172

@szmarczak
Copy link
Owner

It works as expected on Node.js 13

@szmarczak
Copy link
Owner

Fixed in v1.0.0-beta.4.5

@masx200
Copy link
Author

masx200 commented May 7, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants