Skip to content

Commit bc74bec

Browse files
anonrigjasnell
andcommitted
Update src/content/docs/workers/runtime-apis/nodejs/http.mdx
Co-authored-by: James M Snell <[email protected]>
1 parent dfba2b1 commit bc74bec

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

src/content/docs/workers/runtime-apis/nodejs/http.mdx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import { Render } from "~/components"
99

1010
## Agent
1111

12-
An Agent manages HTTP connection reuse by maintaining request queues per host/port. In the
12+
An implementation of the Node.js [`http.Agent'](https://nodejs.org/docs/latest/api/http.html#class-httpagent) class.
13+
14+
An [Agent](https://nodejs.org/docs/latest/api/http.html#class-httpagent) manages HTTP connection reuse by maintaining request queues per host/port. In the
1315
workers environment, however, such low-level management of the network connection, ports,
1416
etc, is not relevant because it is handled by the Cloudflare infrastructure instead. Accordingly, the
1517
implementation of `Agent` in Workers is a stub implementation that does not support connection
@@ -42,15 +44,15 @@ get('http://docs.cloudflare.com/robots.txt', (res) => {
4244
data += chunk;
4345
});
4446
res.on('end', () => {
45-
// Returns the response body as a string.
46-
console.log(data);
4747
ok(data.includes('301 Moved Permanently'));
4848
});
4949
});
5050
```
5151

5252
## request
5353

54+
An implementation of the Node.js [`http.request'](https://nodejs.org/docs/latest/api/http.html#httprequesturl-options-callback) method.
55+
5456
The `request` method creates an HTTP request with customizable options like method, headers, and body. It provides full control over the request configuration and returns a [writable stream](https://nodejs.org/docs/latest/api/stream.html#class-streamwritable) for sending request data.
5557

5658
```js
@@ -63,7 +65,7 @@ const req = request({
6365
hostname: 'docs.cloudflare.com',
6466
path: '/'
6567
}, (res) => {
66-
// http://docs.cloudflare.com redirects to https url.
68+
// requests to http://docs.cloudflare.com get redirected to their https counterpart.
6769
strictEqual(res.statusCode, 301);
6870

6971
let data = '';
@@ -72,21 +74,21 @@ const req = request({
7274
data += chunk;
7375
});
7476
res.on('end', () => {
75-
// Returns the response body as a string.
76-
console.log(data);
7777
ok(data.includes('301 Moved Permanently'));
7878
});
7979
});
8080
req.end();
81+
```
8182

82-
const req2 = request(new URL('http://docs.cloudflare.com'),{
83+
```js
84+
const req = request(new URL('http://docs.cloudflare.com'),{
8385
method: 'GET',
8486
}, (res) => {
85-
// http://docs.cloudflare.com redirects to https url.
87+
// requests to http://docs.cloudflare.com get redirected to their https counterpart.
8688
strictEqual(res.statusCode, 301);
8789
});
8890

89-
req2.end();
91+
req.end();
9092
```
9193

9294
The following options passed to the `request` method are not supported due to the differences in the Cloudflare Workers and the implementation of the `node:http` module:

src/content/docs/workers/runtime-apis/nodejs/https.mdx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import { Render } from "~/components"
99

1010
## Agent
1111

12-
An Agent manages HTTPS connection reuse by maintaining request queues per host/port. In the
12+
An implementation of the Node.js [`https.Agent'](https://nodejs.org/docs/latest/api/https.html#class-httpsagent) class.
13+
14+
An [Agent](https://nodejs.org/docs/latest/api/https.html#class-httpsagent) manages HTTPS connection reuse by maintaining request queues per host/port. In the
1315
workers environment, however, such low-level management of the network connection, ports,
1416
etc, is not relevant because it is handled by the Cloudflare infrastructure instead. Accordingly, the
1517
implementation of `Agent` in Workers is a stub implementation that does not support connection
@@ -25,9 +27,9 @@ strictEqual(agent.protocol, 'https:');
2527

2628
## get
2729

28-
The [`get`](https://nodejs.org/docs/latest/api/https.html#httpsgetoptions-callback) method performs a GET request to the specified URL and invokes the callback with the response. This is a convenience method that simplifies making HTTPS GET requests without manually configuring request options.
30+
An implementation of the Node.js [`https.get'](https://nodejs.org/docs/latest/api/https.html#httpsgetoptions-callback) method.
2931

30-
`get` methods behaves the same as `node:http` get method.
32+
The [`get`](https://nodejs.org/docs/latest/api/https.html#httpsgetoptions-callback) method performs a GET request to the specified URL and invokes the callback with the response. This is a convenience method that simplifies making HTTPS GET requests without manually configuring request options.
3133

3234
```js
3335
import { get } from 'node:https';
@@ -41,24 +43,22 @@ get('https://developers.cloudflare.com/robots.txt', (res) => {
4143
data += chunk;
4244
});
4345
res.on('end', () => {
44-
// Returns the response body as a string.
45-
console.log(data);
4646
ok(data.includes('User-agent'));
4747
});
4848
});
4949
```
5050

5151
## request
5252

53-
The [`request`](https://nodejs.org/docs/latest/api/https.html#httpsrequesturl-options-callback) method creates an HTTPS request with customizable options like method, headers, and body. It provides full control over the request configuration and returns a [writable stream](https://nodejs.org/docs/latest/api/stream.html#class-streamwritable) for sending request data.
53+
An implementation of the Node.js [`https.request'](https://nodejs.org/docs/latest/api/https.html#httpsrequestoptions-callback) method.
54+
55+
The [`request`](https://nodejs.org/docs/latest/api/https.html#httpsrequestoptions-callback) method creates an HTTPS request with customizable options like method, headers, and body. It provides full control over the request configuration and returns a [writable stream](https://developers.cloudflare.com/workers/runtime-apis/streams/writablestream/) for sending request data.
5456

5557
Request method accepts all options from `http.request` with some differences in default values:
5658
- `protocol`: default `https:`
5759
- `port`: default `443`
5860
- `agent`: default `https.globalAgent`
5961

60-
The following additional options are not supported: `ca`, `cert`, `ciphers`, `clientCertEngine` (deprecated), `crl`, `dhparam`, `ecdhCurve`, `honorCipherOrder`, `key`, `passphrase`, `pfx`, `rejectUnauthorized`, `secureOptions`, `secureProtocol`, `servername`, `sessionIdContext`, `highWaterMark`.
61-
6262
```js
6363
import { request } from 'node:https';
6464
import { strictEqual, ok } from 'node:assert';
@@ -73,10 +73,10 @@ const req = request('https://developers.cloudflare.com/robots.txt', {
7373
data += chunk;
7474
});
7575
res.on('end', () => {
76-
// Returns the response body as a string.
77-
console.log(data);
7876
ok(data.includes('User-agent'));
7977
});
8078
});
8179
req.end();
8280
```
81+
82+
The following additional options are not supported: `ca`, `cert`, `ciphers`, `clientCertEngine` (deprecated), `crl`, `dhparam`, `ecdhCurve`, `honorCipherOrder`, `key`, `passphrase`, `pfx`, `rejectUnauthorized`, `secureOptions`, `secureProtocol`, `servername`, `sessionIdContext`, `highWaterMark`.

0 commit comments

Comments
 (0)