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: add esm examples to node:https #54399

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
apply suggestions from code review
mfdebian committed Aug 16, 2024
commit 1b47f73e909b35f14b1bb728dad1788276439721
25 changes: 10 additions & 15 deletions doc/api/https.md
Original file line number Diff line number Diff line change
@@ -249,8 +249,8 @@ import { createServer } from 'node:https';
import { readFileSync } from 'node:fs';

const options = {
key: readFileSync('agent2-key.pem'),
cert: readFileSync('agent2-cert.pem'),
key: readFileSync('private-key.pem'),
cert: readFileSync('certificate.pem'),
};

createServer(options, (req, res) => {
@@ -265,8 +265,8 @@ const https = require('node:https');
const fs = require('node:fs');

const options = {
key: fs.readFileSync('agent2-key.pem'),
cert: fs.readFileSync('agent2-cert.pem'),
key: fs.readFileSync('private-key.pem'),
cert: fs.readFileSync('certificate.pem'),
};

https.createServer(options, (req, res) => {
@@ -311,14 +311,14 @@ To generate the certificate and key for this example, run:

```bash
openssl req -x509 -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' \
-keyout agent2-key.pem -out agent2-cert.pem
-keyout private-key.pem -out certificate.pem
```

Then, to generate the `pfx` certificate for this example, run:

```bash
openssl pkcs12 -certpbe AES-256-CBC -export -out test_cert.pfx \
-inkey agent2-key.pem -in agent2-cert.pem -passout pass:sample
-inkey private-key.pem -in certificate.pem -passout pass:sample
```

## `https.get(options[, callback])`
@@ -517,8 +517,8 @@ const options = {
port: 443,
path: '/',
method: 'GET',
key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem'),
key: fs.readFileSync('private-key.pem'),
cert: fs.readFileSync('certificate.pem'),
};
options.agent = new https.Agent(options);

@@ -535,8 +535,8 @@ const options = {
port: 443,
path: '/',
method: 'GET',
key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem'),
key: fs.readFileSync('private-key.pem'),
cert: fs.readFileSync('certificate.pem'),
agent: false,
};

@@ -621,8 +621,6 @@ options.agent = new Agent(options);
const req = request(options, (res) => {
console.log('All OK. Server matched our pinned cert or public key');
console.log('statusCode:', res.statusCode);
// Print the HPKP values
console.log('headers:', res.headers['strict-transport-security']);

res.on('data', (d) => {});
});
@@ -695,8 +693,6 @@ options.agent = new https.Agent(options);
const req = https.request(options, (res) => {
console.log('All OK. Server matched our pinned cert or public key');
console.log('statusCode:', res.statusCode);
// Print the HPKP values
console.log('headers:', res.headers['strict-transport-security']);

res.on('data', (d) => {});
});
@@ -724,7 +720,6 @@ Subject Common Name: AAA Certificate Services
Public key ping-sha256: vRU+17BDT2iGsXvOi76E7TQMcTLXAqj0+jGPdW7L1vM=
All OK. Server matched our pinned cert or public key
statusCode: 200
headers: max-age=31536000; includeSubdomains; preload
```

[`Agent`]: #class-httpsagent