Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion impit-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ crate-type = ["cdylib"]

[dependencies]
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
napi = { version = "3.0.0-alpha.27", default-features = false, features = ["napi4", "async", "web_stream"] }
napi = { version = "3.0.0-alpha.27", default-features = false, features = ["napi4", "async", "web_stream", "tokio_rt"] }
napi-derive = "3.0.0-alpha.25"
impit = { path="../impit" }
rustls = { version="0.23.16" }
Expand Down
13 changes: 9 additions & 4 deletions impit-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ pub struct ImpitWrapper {
#[napi]
impl ImpitWrapper {
#[napi(constructor)]
pub fn new(options: Option<ImpitOptions>) -> Self {
pub fn new(options: Option<ImpitOptions>) -> Result<Self, napi::Error> {
let config: ImpitBuilder = options.unwrap_or_default().into();

Self {
inner: config.build(),
}
// `quinn` for h3 requires existing async runtime.
// This runs the `config.build` function in the napi-managed tokio runtime which remains available
// throughout the lifetime of the `ImpitWrapper` instance.
napi::bindgen_prelude::block_on(async {
Ok(Self {
inner: config.build(),
})
})
}

#[allow(clippy::missing_safety_doc)] // This method is `unsafe`, but is only ever used from the Node.JS bindings.
Expand Down
18 changes: 18 additions & 0 deletions impit-node/test/basics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ describe.each([

t.expect(json.headers?.['Impit-Test']).toBe('foo');
})

test('http3 works', async (t) => {
const impit = new Impit({
http3: true,
browser,
})

const response = await impit.fetch(
'https://curl.se',
{
forceHttp3: true,
}
);

const text = await response.text();

t.expect(text).toContain('curl');
})
});

describe('HTTP methods', () => {
Expand Down
1 change: 0 additions & 1 deletion impit/src/http_headers/statics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ pub static FIREFOX_HEADERS: &[(&str, &str)] = &[
("sec-fetch-mode", "navigate"),
("sec-fetch-site", "none"),
("sec-fetch-user", "?1"),
("Connection", "keep-alive"),
("Upgrade-Insecure-Requests", "1"),
("Priority", "u=0, i"),
];
Expand Down
Loading