Skip to content
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

feat(http): expose proxy configuration #824

Merged
merged 8 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions .changes/http-proxy-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"http": minor
"http-js": minor
---

The fetch method now exposes a `proxy` field to configure proxy.
cijiugechu marked this conversation as resolved.
Show resolved Hide resolved
54 changes: 27 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions plugins/http/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,38 @@

import { invoke } from "@tauri-apps/api/primitives";

/**
* Configuration of a proxy that a Client should pass requests to.
*
* @since 2.0.0
*/
export interface ProxyConfig {
/**
* Proxy all traffic to the passed URL.
*/
all?: string;
/**
* Proxy all HTTP traffic to the passed URL.
*/
http?: string;
/**
* Proxy all HTTPS traffic to the passed URL.
*/
https?: string;
/**
* Set the `Proxy-Authorization` header using Basic auth.
*/
basicAuth?: {
username: string;
password: string;
};
/**
* A configuration for filtering out requests that shouldn’t be proxied.
* Entries are expected to be comma-separated (whitespace between entries is ignored)
*/
noProxy?: string;
}
amrbashir marked this conversation as resolved.
Show resolved Hide resolved

/**
* Options to configure the Rust client used to make fetch requests
*
Expand All @@ -39,6 +71,10 @@ export interface ClientOptions {
maxRedirections?: number;
/** Timeout in milliseconds */
connectTimeout?: number;
/**
* Configuration of a proxy that a Client should pass requests to.
*/
proxy?: ProxyConfig;
}

/**
Expand All @@ -61,11 +97,13 @@ export async function fetch(
): Promise<Response> {
const maxRedirections = init?.maxRedirections;
const connectTimeout = init?.maxRedirections;
const proxy = init?.proxy;

// Remove these fields before creating the request
if (init) {
delete init.maxRedirections;
delete init.connectTimeout;
delete init.proxy;
}

const req = new Request(input, init);
Expand All @@ -79,6 +117,7 @@ export async function fetch(
data: reqData,
maxRedirections,
connectTimeout,
proxy,
});

req.signal.addEventListener("abort", () => {
Expand Down
2 changes: 1 addition & 1 deletion plugins/http/src/api-iife.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading