forked from axios/axios
-
Notifications
You must be signed in to change notification settings - Fork 2
WIP: Fetch Adapter v2 #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
sgammon
wants to merge
69
commits into
v1.x
Choose a base branch
from
feat/fetch-adapter-v2
base: v1.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
69 commits
Select commit
Hold shift + click to select a range
ab6a697
feat: add `fetch` adapter with cross-platform support
sgammon 728dc27
fix: add polyfill for `AbortController` on Node 14
sgammon 5cea891
chore: add web streams polyfill
sgammon c9427fc
chore: add `whatwg-fetch` polyfill
sgammon 0f36532
feat(fetch): continue with implementation of Fetch adapter + API
sgammon 3624b1f
chore: add karma-coverage for instrumentation
sgammon ab9b529
feat(fetch): implement mock `fetch` for testing
sgammon 2173ebd
feat(fetch): add browser-side test suite
sgammon 6a5c6c7
chore: ignore nyc-output / .husky
sgammon 652ec27
chore: add `FetchAdapter` to ESM export
sgammon 475b418
feat(fetch): update typescript typings with fetch types
sgammon 157c653
feat(fetch): add new `generic` library target (ESM/pure JS)
sgammon 4dfc7a9
feat(fetch): implement structure for abstract fetch testsuite
sgammon a968631
feat(fetch): add Deno benchmark and example
sgammon db1de9b
feat(fetch): add browser example
sgammon 4e04f76
feat(fetch): add minimal browser samples
sgammon e8d6f3e
feat(fetch): add simple Node fetch sample
sgammon 328220a
feat(fetch): add CloudFlare Workers sample
sgammon e1a042d
fix: build matrix, initial ci config for deno testing
sgammon 6637938
fix: drop default fetch cache setting
sgammon 2d6d78d
fix: browser example fixes
sgammon 21f41e8
feat(fetch): platform-driven default adapters for each build
sgammon be92d9d
fix: copy new correct typings for generic bundle
sgammon 41cd5e1
feat(fetch): tools to analyze browser/generic bundle sizes
sgammon d50c5a5
fix: tweaks to Node sample for fetch
sgammon 3347dad
feat(fetch): construction on workers sample for axios/fetch
sgammon b348686
chore: test against Node 19
sgammon 71749db
fix: labs CI matrix
sgammon dce9e02
feat(fetch): platform-specific defaults for `fetchOptions`
sgammon 256195b
fix(fetch): fully mockable responses for fetch testing
sgammon b2d419c
fix: tweaks to fetch examples
sgammon 1a6e074
feat(fetch): fetch example improvements + READMEs (browser, deno)
sgammon 690be1c
feat(fetch): only ship .d.cts with non-modern targets
sgammon 20b5633
feat(fetch): add explicit `axios/generic` bundle export
sgammon 272f066
feat(fetch): variants and README for node fetch examples
sgammon 58a2fc4
feat(fetch): better debug logging, assertions, support for `Blob`
sgammon 503c724
feat(fetch): allow importing specific files for generic bundle
sgammon 683469e
feat(fetch): document new fetch config in main README
sgammon 100d31b
fix(fetch): refactor and cleanup response handler selection
sgammon 3927308
fix(fetch): fixes for Fetch adapter in CloudFlare Workers env
sgammon 0bc7dde
feat(fetch): sample for CloudFlare Workers
sgammon ae2ebe7
chore: add doc for workers sample
sgammon 6e40e17
chore: updates to main README docs
sgammon 9b8692c
feat(fetch): pure-ESM web testing
sgammon ce16244
chore: add bundle sizes for generic entrypoint
sgammon faede9b
chore: additional bundle size testing
sgammon da2308b
feat: export utils as individual symbols
sgammon 2b9bed3
fix(fetch): avoid re-defining any variables named 'fetch'
sgammon f375b92
feat(fetch): treeshaking and terser tweaks, optimize license
sgammon 4b1c994
fix: don't require Content-Type for body
sgammon 181ebe9
feat(fetch): improvements to fetch typings
sgammon 9bbd0b0
chore: cleanup abstract fetch testsuite
sgammon 1ffc76e
fix: keep console debug statements during beta
sgammon e7d33a3
fix: 'modern' export profile types
sgammon eed4e5e
chore: smaller bundle size limits
sgammon b40c7c6
fix: handler selection with no `Content-Type` present
sgammon e0fddb0
fix: errors with previous typing updates
sgammon cdc1b3c
chore: drop unused webpack config
sgammon b1e4a3e
chore: package spec cleanup
sgammon fcb5351
chore: setup CI testing for Bun
sgammon de21e6d
fix: polynomial-capable regex in combineURLs helper
sgammon 3fcd8cc
fix: pass relative URLs directly to the underlying fetcher
sgammon 80d24e9
test: ESM API spec
sgammon a2d11ed
chore: cleanup abstract fetch testsuite
sgammon c6fa931
fix: disable protocol-relative URL testing for combineURLs (temp)
sgammon 135495a
fix: drop missing test
sgammon ccfb365
fix: allow version tag in user-agent test
sgammon f7e700f
chore: version bump for `fetch` testing → `1.5.0-fetch`
sgammon 9b315e1
chore: lock packages, rebuild dist
sgammon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: 'CI: Labs' | ||
|
||
on: | ||
push: | ||
branches: '**' | ||
pull_request: | ||
branches: '**' | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
engine: [deno] | ||
version: [v1.x] | ||
mode: [labs] | ||
include: | ||
- engine: deno | ||
version: v1.x | ||
- engine: node | ||
version: 19.x | ||
mode: labs | ||
- engine: bun | ||
version: 0.3.0 | ||
mode: labs | ||
Comment on lines
+27
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test task missing for bun |
||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
persist-credentials: false | ||
|
||
## --- Runtime Setup | ||
|
||
- name: Setup node | ||
uses: actions/setup-node@v3 | ||
if: ${{ matrix.engine == 'node' }} | ||
with: | ||
node-version: ${{ matrix.version }} | ||
cache: npm | ||
- name: Setup Deno | ||
uses: denoland/setup-deno@v1 | ||
if: ${{ matrix.engine == 'deno' }} | ||
with: | ||
deno-version: ${{ matrix.version }} | ||
- name: Setup Bun | ||
uses: antongolub/action-setup-bun@v1 | ||
if: ${{ matrix.engine == 'bun' }} | ||
with: | ||
bun-version: ${{ matrix.version }} | ||
|
||
## --- Build + Test | ||
|
||
- run: npm install | ||
- run: npm run build | ||
if: ${{ matrix.engine == 'deno' }} | ||
- run: npm run test:${{ matrix.engine }} | ||
continue-on-error: ${{ matrix.mode == 'labs' }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,5 @@ backup/ | |
/.husky/ | ||
.npmrc | ||
.env | ||
.husky/ | ||
.nyc_output/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,8 @@ | |
## Features | ||
|
||
- Make [XMLHttpRequests](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) from the browser | ||
- Make [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) requests from the browser, node.js, or pure-JS | ||
runtimes like Workers, Deno, Bun, etc. | ||
- Make [http](https://nodejs.org/api/http.html) requests from node.js | ||
- Supports the [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) API | ||
- Intercept request and response | ||
|
@@ -165,6 +167,23 @@ Using unpkg CDN: | |
<script src="https://unpkg.com/[email protected]/dist/axios.min.js"></script> | ||
``` | ||
|
||
### Pure JS environments | ||
|
||
Using Axios in **Deno**: | ||
```js | ||
import axios from "https://cdn.jsdelivr.net/npm/[email protected]/dist/generic/axios.min.mjs"; | ||
``` | ||
|
||
Using in CloudFlare Workers, Bun, and other environments which support the Fetch API: | ||
```js | ||
{npm|pnpm|yarn} install axios | ||
``` | ||
|
||
Then: | ||
```js | ||
import axios from "axios/generic"; | ||
``` | ||
|
||
## Example | ||
|
||
> **Note**: CommonJS usage | ||
|
@@ -286,6 +305,9 @@ axios({ | |
```js | ||
// Send a GET request (default method) | ||
axios('/user/12345'); | ||
|
||
// You can also use a `URL` object | ||
axios(new URL('https://example.com/user/12345')); | ||
``` | ||
|
||
### Request method aliases | ||
|
@@ -346,7 +368,8 @@ These are the available config options for making requests. Only the `url` is re | |
|
||
```js | ||
{ | ||
// `url` is the server URL that will be used for the request | ||
// `url` is the server URL that will be used for the request. you can | ||
// also pass `new URL(...)`, in environments that support it. | ||
url: '/user', | ||
|
||
// `method` is the request method to be used when making the request | ||
|
@@ -538,6 +561,114 @@ These are the available config options for making requests. Only the `url` is re | |
// an alternative way to cancel Axios requests using AbortController | ||
signal: new AbortController().signal, | ||
|
||
// pre-parsed URL, to avoid re-parsing the URL when using the fetch adapter. | ||
// optional. | ||
parsedUrl: new URL('...'), | ||
|
||
// fetch implementation to use. defaults to the native fetch implementation for | ||
// the active platform, or falls back to a polyfill (`whatwg-fetch`), or a cross- | ||
// platform polyfill (`cross-fetch`). | ||
fetcher: fetch, | ||
|
||
// options passed to the underlying `fetch` implementation; only active when | ||
// `adapter` is set to `{adapter: 'fetch'}` or `{adapter: axios.FetchAdapter}`. | ||
// default values below are for `fetch` implementation in browsers. certain fetch | ||
// implementations may require different or limited options. | ||
// | ||
// see MDN for more information (`options` parameter): | ||
// https://developer.mozilla.org/en-US/docs/Web/API/Request/Request | ||
fetchOptions: { | ||
// the general request mode to apply to an operation. options are: | ||
// - `cors` (default): allow cross-origin requests. | ||
// - `no-cors`: do not allow cross-origin requests. | ||
// - `same-origin`: only allow requests to the same origin. | ||
// | ||
// MDN: https://developer.mozilla.org/en-US/docs/Web/API/Request/mode | ||
mode: 'cors', | ||
|
||
// should the user's credentials and cookies be sent with the request? options are: | ||
// - `same-origin` (default): only send for same-origin requests. | ||
// - `include`: include credentials for all requests. | ||
// - `omit`: do not send credentials. | ||
// | ||
// DANGER: Be careful with this property. Setting the request to `include` can expose | ||
// users to serious privacy and security risks. Make sure the origins you are exchanging | ||
// data with use HTTPS and are covered by other strong security practices. | ||
// | ||
// MDN: https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials | ||
credentials: 'same-origin', | ||
|
||
// allow caching of fetched responses? options are: | ||
// - `default` (default): default environment behavior. in browsers, caching | ||
// is typically enabled for GET requests that are marked cacheable. | ||
// - `no-store`: do not store responses in cache. | ||
// - `reload`: fetch from server and update cache. | ||
// - `no-cache`: fetch from server and do not update cache. | ||
// - `force-cache`: use cache if available, otherwise fetch from server and | ||
// update the cache. | ||
// - `only-if-cached`: use cache if available, otherwise fail. this mode can | ||
// only be used when `mode` is set to `same-origin`. | ||
// | ||
// MDN: https://developer.mozilla.org/en-US/docs/Web/API/Request/cache | ||
cache: 'default', | ||
|
||
// follow redirects returned in fetch calls? options are: | ||
// - `follow` (default): follow redirects | ||
// - `error`: reject with an error | ||
// - `manual`: handle redirects manually | ||
// | ||
// MDN: https://developer.mozilla.org/en-US/docs/Web/API/Request/redirect | ||
redirect: 'follow', | ||
|
||
// what referrer, if any, should be sent with requests? options are: | ||
// - `about:client` (default): anonymized referrer is sent. | ||
// - `no-referrer`: no referrer is sent. | ||
// - `client`: full referrer is sent. | ||
// - `<url>`: a custom URL value can be set and sent. | ||
// | ||
// See also: `referrerPolicy`. | ||
// | ||
// MDN: https://developer.mozilla.org/en-US/docs/Web/API/Request/referrer | ||
referrer: 'about:client', | ||
|
||
// what policy should be applied when deciding whether to send a referrer? options are: | ||
// - `strict-origin-when-cross-origin` (default): send the origin, path, and querystring | ||
// when performing same-origin requests. For cross-origin requests, send only the origin. | ||
// The referrer is never sent to non-secure origins in this mode. | ||
// - `no-referrer-when-downgrade`: send referrer only when navigating to a more or | ||
// equivalently secure origin. | ||
// - `no-referrer`: never send a referrer. | ||
// - `origin`: send the origin only. | ||
// - `origin-when-cross-origin`: send only the origin when interacting with a different origin. | ||
// - `same-origin`: send the referrer only when interacting with same-origin endpoints. | ||
// - `strict-origin`: send the origin only when the protocol level stays the same. | ||
// - `unsafe-url`: send the full referrer URL unconditionally to all origins. | ||
// | ||
// See also: https://developer.mozilla.org/en-US/docs/Web/API/Request/referrerPolicy | ||
referrerPolicy: 'strict-origin-when-cross-origin', | ||
|
||
// should an integrity value be applied and checked for the request? options are: | ||
// - no value (default): no integrity is checked. | ||
// - `<hash-algorithm>-<base64-value>`: integrity is checked using the specified algorithm. | ||
// for example, `sha256-<hash>`. | ||
// | ||
// MDN: https://developer.mozilla.org/en-US/docs/Web/API/Request/integrity | ||
integrity: 'sha256-<base64-encoded-hash>', | ||
|
||
// should the connection to the server be kept alive? options are: | ||
// - true (default): keep the connection alive. | ||
// - false: close the connection after the request is complete. | ||
// MDN: https://developer.mozilla.org/en-US/docs/Web/API/Request/Request | ||
keepalive: true, | ||
|
||
// an `AbortSignal` object which can be used to communicate with or abort the request; | ||
// if both this property and the main config `signal` property are set, this property | ||
// takes precedence. | ||
// | ||
// MDN: https://developer.mozilla.org/en-US/docs/Web/API/Request/signal | ||
signal: new AbortController().signal | ||
}, | ||
|
||
// `decompress` indicates whether or not the response body should be decompressed | ||
// automatically. If set to `true` will also remove the 'content-encoding' header | ||
// from the responses objects of all decompressed responses | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timeout bug on node 19