Skip to content

Commit 2a2d7ea

Browse files
committed
remove unused stuff
1 parent 9134ee6 commit 2a2d7ea

File tree

3,287 files changed

+9
-242380
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,287 files changed

+9
-242380
lines changed

README.md

-238
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,6 @@ Should you need to access the `body` in plain-text after using a mixin, the best
114114

115115
For more information about their behavior, please reference the body mixin from the [Fetch Standard](https://fetch.spec.whatwg.org/#body-mixin).
116116

117-
## Common API Methods
118-
119-
This section documents our most commonly used API methods. Additional APIs are documented in their own files within the [docs](./docs/) folder and are accessible via the navigation list on the left side of the docs site.
120-
121117
### `undici.request([url, options]): Promise`
122118

123119
Arguments:
@@ -134,218 +130,6 @@ Calls `options.dispatcher.request(options)`.
134130

135131
See [Dispatcher.request](./docs/docs/api/Dispatcher.md#dispatcherrequestoptions-callback) for more details, and [request examples](./examples/README.md) for examples.
136132

137-
### `undici.stream([url, options, ]factory): Promise`
138-
139-
Arguments:
140-
141-
* **url** `string | URL | UrlObject`
142-
* **options** [`StreamOptions`](./docs/docs/api/Dispatcher.md#parameter-streamoptions)
143-
* **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcher)
144-
* **method** `String` - Default: `PUT` if `options.body`, otherwise `GET`
145-
* **maxRedirections** `Integer` - Default: `0`
146-
* **factory** `Dispatcher.stream.factory`
147-
148-
Returns a promise with the result of the `Dispatcher.stream` method.
149-
150-
Calls `options.dispatcher.stream(options, factory)`.
151-
152-
See [Dispatcher.stream](./docs/docs/api/Dispatcher.md#dispatcherstreamoptions-factory-callback) for more details.
153-
154-
### `undici.pipeline([url, options, ]handler): Duplex`
155-
156-
Arguments:
157-
158-
* **url** `string | URL | UrlObject`
159-
* **options** [`PipelineOptions`](./docs/docs/api/Dispatcher.md#parameter-pipelineoptions)
160-
* **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcher)
161-
* **method** `String` - Default: `PUT` if `options.body`, otherwise `GET`
162-
* **maxRedirections** `Integer` - Default: `0`
163-
* **handler** `Dispatcher.pipeline.handler`
164-
165-
Returns: `stream.Duplex`
166-
167-
Calls `options.dispatch.pipeline(options, handler)`.
168-
169-
See [Dispatcher.pipeline](./docs/docs/api/Dispatcher.md#dispatcherpipelineoptions-handler) for more details.
170-
171-
### `undici.connect([url, options]): Promise`
172-
173-
Starts two-way communications with the requested resource using [HTTP CONNECT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/CONNECT).
174-
175-
Arguments:
176-
177-
* **url** `string | URL | UrlObject`
178-
* **options** [`ConnectOptions`](./docs/docs/api/Dispatcher.md#parameter-connectoptions)
179-
* **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcher)
180-
* **maxRedirections** `Integer` - Default: `0`
181-
* **callback** `(err: Error | null, data: ConnectData | null) => void` (optional)
182-
183-
Returns a promise with the result of the `Dispatcher.connect` method.
184-
185-
Calls `options.dispatch.connect(options)`.
186-
187-
See [Dispatcher.connect](./docs/docs/api/Dispatcher.md#dispatcherconnectoptions-callback) for more details.
188-
189-
### `undici.fetch(input[, init]): Promise`
190-
191-
Implements [fetch](https://fetch.spec.whatwg.org/#fetch-method).
192-
193-
* https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch
194-
* https://fetch.spec.whatwg.org/#fetch-method
195-
196-
Basic usage example:
197-
198-
```js
199-
import { fetch } from 'undici'
200-
201-
202-
const res = await fetch('https://example.com')
203-
const json = await res.json()
204-
console.log(json)
205-
```
206-
207-
You can pass an optional dispatcher to `fetch` as:
208-
209-
```js
210-
import { fetch, Agent } from 'undici'
211-
212-
const res = await fetch('https://example.com', {
213-
// Mocks are also supported
214-
dispatcher: new Agent({
215-
keepAliveTimeout: 10,
216-
keepAliveMaxTimeout: 10
217-
})
218-
})
219-
const json = await res.json()
220-
console.log(json)
221-
```
222-
223-
#### `request.body`
224-
225-
A body can be of the following types:
226-
227-
- ArrayBuffer
228-
- ArrayBufferView
229-
- AsyncIterables
230-
- Blob
231-
- Iterables
232-
- String
233-
- URLSearchParams
234-
- FormData
235-
236-
In this implementation of fetch, ```request.body``` now accepts ```Async Iterables```. It is not present in the [Fetch Standard.](https://fetch.spec.whatwg.org)
237-
238-
```js
239-
import { fetch } from 'undici'
240-
241-
const data = {
242-
async *[Symbol.asyncIterator]() {
243-
yield 'hello'
244-
yield 'world'
245-
},
246-
}
247-
248-
await fetch('https://example.com', { body: data, method: 'POST', duplex: 'half' })
249-
```
250-
251-
[FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData) besides text data and buffers can also utilize streams via [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) objects:
252-
253-
```js
254-
import { openAsBlob } from 'node:fs'
255-
256-
const file = await openAsBlob('./big.csv')
257-
const body = new FormData()
258-
body.set('file', file, 'big.csv')
259-
260-
await fetch('http://example.com', { method: 'POST', body })
261-
```
262-
263-
#### `request.duplex`
264-
265-
- half
266-
267-
In this implementation of fetch, `request.duplex` must be set if `request.body` is `ReadableStream` or `Async Iterables`, however, fetch requests are currently always full duplex. For more detail refer to the [Fetch Standard.](https://fetch.spec.whatwg.org/#dom-requestinit-duplex).
268-
269-
#### `response.body`
270-
271-
Nodejs has two kinds of streams: [web streams](https://nodejs.org/dist/latest-v16.x/docs/api/webstreams.html), which follow the API of the WHATWG web standard found in browsers, and an older Node-specific [streams API](https://nodejs.org/api/stream.html). `response.body` returns a readable web stream. If you would prefer to work with a Node stream you can convert a web stream using `.fromWeb()`.
272-
273-
```js
274-
import { fetch } from 'undici'
275-
import { Readable } from 'node:stream'
276-
277-
const response = await fetch('https://example.com')
278-
const readableWebStream = response.body
279-
const readableNodeStream = Readable.fromWeb(readableWebStream)
280-
```
281-
282-
#### Specification Compliance
283-
284-
This section documents parts of the [Fetch Standard](https://fetch.spec.whatwg.org) that Undici does
285-
not support or does not fully implement.
286-
287-
##### Garbage Collection
288-
289-
* https://fetch.spec.whatwg.org/#garbage-collection
290-
291-
The [Fetch Standard](https://fetch.spec.whatwg.org) allows users to skip consuming the response body by relying on
292-
[garbage collection](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management#garbage_collection) to release connection resources. Undici does not do the same. Therefore, it is important to always either consume or cancel the response body.
293-
294-
Garbage collection in Node is less aggressive and deterministic
295-
(due to the lack of clear idle periods that browsers have through the rendering refresh rate)
296-
which means that leaving the release of connection resources to the garbage collector can lead
297-
to excessive connection usage, reduced performance (due to less connection re-use), and even
298-
stalls or deadlocks when running out of connections.
299-
300-
```js
301-
// Do
302-
const headers = await fetch(url)
303-
.then(async res => {
304-
for await (const chunk of res.body) {
305-
// force consumption of body
306-
}
307-
return res.headers
308-
})
309-
310-
// Do not
311-
const headers = await fetch(url)
312-
.then(res => res.headers)
313-
```
314-
315-
However, if you want to get only headers, it might be better to use `HEAD` request method. Usage of this method will obviate the need for consumption or cancelling of the response body. See [MDN - HTTP - HTTP request methods - HEAD](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD) for more details.
316-
317-
```js
318-
const headers = await fetch(url, { method: 'HEAD' })
319-
.then(res => res.headers)
320-
```
321-
322-
##### Forbidden and Safelisted Header Names
323-
324-
* https://fetch.spec.whatwg.org/#cors-safelisted-response-header-name
325-
* https://fetch.spec.whatwg.org/#forbidden-header-name
326-
* https://fetch.spec.whatwg.org/#forbidden-response-header-name
327-
* https://github.com/wintercg/fetch/issues/6
328-
329-
The [Fetch Standard](https://fetch.spec.whatwg.org) requires implementations to exclude certain headers from requests and responses. In browser environments, some headers are forbidden so the user agent remains in full control over them. In Undici, these constraints are removed to give more control to the user.
330-
331-
### `undici.upgrade([url, options]): Promise`
332-
333-
Upgrade to a different protocol. See [MDN - HTTP - Protocol upgrade mechanism](https://developer.mozilla.org/en-US/docs/Web/HTTP/Protocol_upgrade_mechanism) for more details.
334-
335-
Arguments:
336-
337-
* **url** `string | URL | UrlObject`
338-
* **options** [`UpgradeOptions`](./docs/docs/api/Dispatcher.md#parameter-upgradeoptions)
339-
* **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcher)
340-
* **maxRedirections** `Integer` - Default: `0`
341-
* **callback** `(error: Error | null, data: UpgradeData) => void` (optional)
342-
343-
Returns a promise with the result of the `Dispatcher.upgrade` method.
344-
345-
Calls `options.dispatcher.upgrade(options)`.
346-
347-
See [Dispatcher.upgrade](./docs/docs/api/Dispatcher.md#dispatcherupgradeoptions-callback) for more details.
348-
349133
### `undici.setGlobalDispatcher(dispatcher)`
350134

351135
* dispatcher `Dispatcher`
@@ -358,28 +142,6 @@ Gets the global dispatcher used by Common API Methods.
358142

359143
Returns: `Dispatcher`
360144

361-
### `undici.setGlobalOrigin(origin)`
362-
363-
* origin `string | URL | undefined`
364-
365-
Sets the global origin used in `fetch`.
366-
367-
If `undefined` is passed, the global origin will be reset. This will cause `Response.redirect`, `new Request()`, and `fetch` to throw an error when a relative path is passed.
368-
369-
```js
370-
setGlobalOrigin('http://localhost:3000')
371-
372-
const response = await fetch('/api/ping')
373-
374-
console.log(response.url) // http://localhost:3000/api/ping
375-
```
376-
377-
### `undici.getGlobalOrigin()`
378-
379-
Gets the global origin used in `fetch`.
380-
381-
Returns: `URL`
382-
383145
### `UrlObject`
384146

385147
* **port** `string | number` (optional)

docs/.nojekyll

Whitespace-only changes.

docs/CNAME

-1
This file was deleted.

docs/README.md

-1
This file was deleted.

docs/docs/api/Agent.md

-80
This file was deleted.

0 commit comments

Comments
 (0)