Comparing version 12.0.2 to 12.0.3
@@ -11,3 +11,5 @@ "use strict"; | ||
return function fetch(...args) { | ||
const req = args[0] instanceof Request ? args[0] : new Request(...args); | ||
const req = args.length === 1 && args[0] instanceof Request | ||
? args[0] | ||
: new Request(...args); | ||
return middleware(req, done); | ||
@@ -14,0 +16,0 @@ }; |
{ | ||
"name": "popsicle", | ||
"version": "12.0.2", | ||
"version": "12.0.3", | ||
"description": "Advanced HTTP requests in node.js and browsers", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -28,15 +28,33 @@ # ![Popsicle](https://cdn.rawgit.com/serviejs/popsicle/master/logo.svg) | ||
Popsicle re-exports `Request`, `Response`, `Headers` and `AbortController` from [`servie`](https://github.com/serviejs/servie). The `fetch` function accepts the same arguments as [`Request`](https://github.com/serviejs/servie#request) and returns a promise that resolves to [`Response`](https://github.com/serviejs/servie#response). You can use the [`Signal`](https://github.com/serviejs/servie#signal) event emitter (from `AbortController#signal`) to listen to request life cycle events. | ||
### [Browser](./src/browser.ts) | ||
The middleware stack for browsers contains _only_ the transport layer. This makes the package tiny and quick on browsers. | ||
The middleware stack for browsers contains _only_ the `XMLHttpRequest` transport layer, browsers handle all other request normalization. This means a smaller and faster package for browsers. | ||
### [Node.js](./src/node.ts) | ||
The middleware stack for node.js includes a lot more normalization to act similar to browsers: | ||
The middleware stack for node.js includes normalization to act similar to browsers: | ||
- Default `User-Agent` initialization | ||
- Default decoding of compressed responses | ||
- Follows valid HTTP redirects | ||
- Default `User-Agent` | ||
- Support for decoding compressed payloads | ||
- Follows HTTP redirects | ||
- Caches cookies in-memory | ||
### Recipes | ||
#### Aborting a Request | ||
```ts | ||
import { fetch, AbortController } from "popsicle"; | ||
const controller = new AbortController(); | ||
setTimeout(() => controller.abort(), 500); | ||
const res = fetch("http://example.com", { | ||
signal: controller.signal | ||
}); | ||
``` | ||
### Errors | ||
@@ -43,0 +61,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23327
145
103