Skip to content

Commit d676df7

Browse files
feat(http): add HTTP2 support; (#7150)
1 parent 015faec commit d676df7

8 files changed

Lines changed: 731 additions & 159 deletions

File tree

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
- [🔥 Custom fetch](#-custom-fetch)
8888
- [🔥 Using with Tauri](#-using-with-tauri)
8989
- [🔥 Using with SvelteKit](#-using-with-sveltekit-)
90+
- [🔥 HTTP2](#-http2)
9091
- [Semver](#semver)
9192
- [Promises](#promises)
9293
- [TypeScript](#typescript)
@@ -1702,6 +1703,34 @@ export async function load({ fetch }) {
17021703
}
17031704
```
17041705
1706+
## 🔥 HTTP2
1707+
1708+
In version `1.13.0`, experimental `HTTP2` support was added to the `http` adapter.
1709+
The `httpVersion` option is now available to select the protocol version used.
1710+
Additional native options for the internal `session.request()` call can be passed via the `http2Options` config.
1711+
This config also includes the custom `sessionTimeout` parameter, which defaults to `1000ms`.
1712+
1713+
```js
1714+
const form = new FormData();
1715+
1716+
form.append('foo', '123');
1717+
1718+
const {data, headers, status} = await axios.post('https://httpbin.org/post', form, {
1719+
httpVersion: 2,
1720+
http2Options: {
1721+
// rejectUnauthorized: false,
1722+
// sessionTimeout: 1000
1723+
},
1724+
onUploadProgress(e) {
1725+
console.log('upload progress', e);
1726+
},
1727+
onDownloadProgress(e) {
1728+
console.log('download progress', e);
1729+
},
1730+
responseType: 'arraybuffer'
1731+
});
1732+
```
1733+
17051734
## Semver
17061735
17071736
Since Axios has reached a `v.1.0.0` we will fully embrace semver as per the spec [here](https://semver.org/)

index.d.cts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,10 @@ declare namespace axios {
436436
((hostname: string, options: object) => Promise<[address: LookupAddressEntry | LookupAddressEntry[], family?: AddressFamily] | LookupAddress>);
437437
withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig) => boolean | undefined);
438438
fetchOptions?: Omit<RequestInit, 'body' | 'headers' | 'method' | 'signal'> | Record<string, any>;
439+
httpVersion?: 1 | 2;
440+
http2Options?: Record<string, any> & {
441+
sessionTimeout?: number;
442+
};
439443
}
440444

441445
// Alias

index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ export interface AxiosRequestConfig<D = any> {
369369
withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig) => boolean | undefined);
370370
parseReviver?: (this: any, key: string, value: any) => any;
371371
fetchOptions?: Omit<RequestInit, 'body' | 'headers' | 'method' | 'signal'> | Record<string, any>;
372+
httpVersion?: 1 | 2;
373+
http2Options?: Record<string, any> & {
374+
sessionTimeout?: number;
375+
};
372376
}
373377

374378
// Alias

0 commit comments

Comments
 (0)