You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For `string`and `Buffer` types, the `content-length` header is automatically set if the `content-length` and `transfer-encoding` headers are missing.
300
+
For `string`, `Buffer`, and `TypedArray` types (Uint8Array, Uint16Array, etc.), the `content-length` header is automatically set if the `content-length` and `transfer-encoding` headers are missing.
301
301
302
302
**The `content-length` header is not automatically set when `body` is an instance of [`fs.createReadStream()`](https://nodejs.org/api/fs.html#fs_fs_createreadstream_path_options).**
303
303
@@ -331,6 +331,21 @@ console.log(data);
331
331
//=> 'Hello, world!'
332
332
```
333
333
334
+
You can also use typed arrays (Uint8Array, Uint16Array, etc.) as request body:
335
+
336
+
```js
337
+
importgotfrom'got';
338
+
339
+
constuint8Body=newUint8Array([104, 101, 108, 108, 111]); // 'hello' in ASCII
You can use `Iterable` and `AsyncIterable` objects as request body, including Web [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream):
Copy file name to clipboardExpand all lines: source/core/options.ts
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1410,7 +1410,7 @@ export default class Options {
1410
1410
1411
1411
__Note #4__: This option is not enumerable and will not be merged with the instance defaults.
1412
1412
1413
-
The `content-length` header will be automatically set if `body` is a `string` / `Buffer` / [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) / [`form-data` instance](https://github.com/form-data/form-data), and `content-length` and `transfer-encoding` are not manually set in `options.headers`.
1413
+
The `content-length` header will be automatically set if `body` is a `string` / `Buffer` / typed array ([`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array), etc.) / [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) / [`form-data` instance](https://github.com/form-data/form-data), and `content-length` and `transfer-encoding` are not manually set in `options.headers`.
1414
1414
1415
1415
Since Got 12, the `content-length` is not automatically set when `body` is a `fs.createReadStream`.
1416
1416
@@ -1431,12 +1431,12 @@ export default class Options {
0 commit comments