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

doc:"HTTP/2" The instance localhost did not send any data. #3525

Closed
iusx opened this issue Sep 2, 2021 · 2 comments
Closed

doc:"HTTP/2" The instance localhost did not send any data. #3525

iusx opened this issue Sep 2, 2021 · 2 comments

Comments

@iusx
Copy link

iusx commented Sep 2, 2021

version: v10.24.0、v14.17.6
System: Linux kunlun 4.19.0-17-amd64 nodejs/nodejs.org#1 SMP Debian 4.19.194-3 (2021-07-18) x86_64 GNU/Linux
Issue: HTTP/2
Url: https://nodejs.org/api/http2.html

describe

node/
├── package.json
├── public
├── src
│   └── server.js
└── ssl
    ├── localhost-cert.pem
    └── localhost-privkey.pem

const http2 = require('http2');
const fs = require('fs');

const server = http2.createSecureServer({
    key: fs.readFileSync('./ssl/localhost-privkey.pem'),
    cert: fs.readFileSync('./ssl/localhost-cert.pem')
});
server.on('error', (err) => console.error(err));

server.on('stream', (stream, headers) => {
    // stream is a Duplex
    stream.respond({
        'content-type': 'text/html; charset=utf-8',
        ':status': 200
    });
    stream.write('<h1>Hello,world!</h1>')
    stream.end();
});

server.listen(8443);

I wrote it according to the example in the HTTP/2 document. It did not make a mistake, but when I visited localhost:8443, the browser returned: "localhost did not send any data."

I found on npm that the http2 module has been deprecated. Is it caused by this? Is there any alternative? Because I’m learning node recently, the HTTP2 described in the book supports multiplexing, header compression, service push and other features, which can reduce a lot of overhead, which is very important to me.

@nschonni nschonni transferred this issue from nodejs/nodejs.org Sep 2, 2021
@Ayase-252
Copy link
Member

You may have to visit with URL https://localhost:8443 (there may be a privacy error, since a self-signed certficate are used in the demo. You could trust the certificate temporarily to see what will happen).

I found on npm that the http2 module has been deprecated. Is it caused by this?

No, http2 is a built-in module of Node.js, and is not related to http2 on npm.

@iusx
Copy link
Author

iusx commented Sep 3, 2021

https://localhost:8443

Thanks for your answer, this solved my problem in a way never thought of

@iusx iusx closed this as completed Sep 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants