Browse Source

doc: modernize and fix code examples in https.md

* Replace `var` by `const`.
* Comment out ellipses.
* Update code example (provide relevant file path, add missing option).

PR-URL: https://github.com/nodejs/node/pull/12171
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
v6
Vse Mozhet Byt 8 years ago
parent
commit
505936309d
  1. 19
      doc/api/https.md

19
doc/api/https.md

@ -70,7 +70,8 @@ const https = require('https');
const fs = require('fs'); const fs = require('fs');
const options = { const options = {
pfx: fs.readFileSync('server.pfx') pfx: fs.readFileSync('test/fixtures/test_cert.pfx'),
passphrase: 'sample'
}; };
https.createServer(options, (req, res) => { https.createServer(options, (req, res) => {
@ -167,14 +168,14 @@ Example:
```js ```js
const https = require('https'); const https = require('https');
var options = { const options = {
hostname: 'encrypted.google.com', hostname: 'encrypted.google.com',
port: 443, port: 443,
path: '/', path: '/',
method: 'GET' method: 'GET'
}; };
var req = https.request(options, (res) => { const req = https.request(options, (res) => {
console.log('statusCode:', res.statusCode); console.log('statusCode:', res.statusCode);
console.log('headers:', res.headers); console.log('headers:', res.headers);
@ -191,7 +192,7 @@ req.end();
Example using options from [`tls.connect()`][]: Example using options from [`tls.connect()`][]:
```js ```js
var options = { const options = {
hostname: 'encrypted.google.com', hostname: 'encrypted.google.com',
port: 443, port: 443,
path: '/', path: '/',
@ -201,8 +202,8 @@ var options = {
}; };
options.agent = new https.Agent(options); options.agent = new https.Agent(options);
var req = https.request(options, (res) => { const req = https.request(options, (res) => {
... // ...
}); });
``` ```
@ -211,7 +212,7 @@ Alternatively, opt out of connection pooling by not using an `Agent`.
Example: Example:
```js ```js
var options = { const options = {
hostname: 'encrypted.google.com', hostname: 'encrypted.google.com',
port: 443, port: 443,
path: '/', path: '/',
@ -221,8 +222,8 @@ var options = {
agent: false agent: false
}; };
var req = https.request(options, (res) => { const req = https.request(options, (res) => {
... // ...
}); });
``` ```

Loading…
Cancel
Save