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] Proxy support in fetch function in tauri's http API #6467

Closed
allala0 opened this issue Mar 16, 2023 · 7 comments
Closed

[feat] Proxy support in fetch function in tauri's http API #6467

allala0 opened this issue Mar 16, 2023 · 7 comments

Comments

@allala0
Copy link

allala0 commented Mar 16, 2023

Describe the problem

There is no support for using proxies in fetch function in tauri's http API.

Describe the solution you'd like

Support proxies with and without authentication in fetch function in tauri's http API.
Proxy will be one of feth's function parameters, and could be passed with authentication data like: "username:password@host:port" or without authentication data: "host:port".
Example of fetch function call with proxy parameter:

const response = await fetch("https://www.google.com", { method: "GET", proxy: "admin:admin@123.123.321.321:8080" });

Alternatives considered

No response

Additional context

This feature is frequently needed when app includes some web scraping, I personally started coding my own project in Tauri, but lack of proxy supprort is blocking me right now from finishing the project :/

@maku
Copy link

maku commented Mar 20, 2023

I would also need to be able to set a proxy.

But to be clear: this option should also to be available for the client you create via getClient() from "@tauri-apps/api/http"

@yizhiyan
Copy link

I think this design would be better

const response = await fetch("https://www.google.com", { method: "GET", proxy: "http://admin:admin@123.123.321.321:8080" });

It would be even better if you could set the proxy type

@FabianLars
Copy link
Member

It would be even better if you could set the proxy type

What types are there? And do you have an idea how it should look like api wise?

On that topic, do you guys have examples from other libraries that support this and where you like the api design?

@ugger0101
Copy link

if you use external Js modules, such as axios + socks-proxy-agent, that may be able to meet your needs. Unfortunately, it works in theory and has been verified in electron, but it does not work in tauri.
I think it may be a problem in my code or that the webview-based tauri is different from the eletron which based nodejs, but I recommend you try it anyway

@Pylogmon
Copy link
Contributor

Pylogmon commented May 8, 2023

I found that setting environment variables in the code is useful for tauri/http, but it has no effect for ajax

std::env::set_var("HTTP_PROXY","http://127.0.0.1:7890");
std::env::set_var("HTTPS_PROXY","http://127.0.0.1:7890");
std::env::set_var("ALL_PROXY","http://127.0.0.1:7890");

@iwinux
Copy link

iwinux commented Jul 18, 2023

On macOS, if you start the app with yarn tauri dev or open foo.app from CLI, the app picks up existing http_proxy and https_proxy environment variables properly, and http.fetch() uses the proxy as expected.

However, when the app is launched directly, it has no access to these environment variables. It should have respected macOS system proxy settings instead of relying on environment variables, just as other native apps do.

@amrbashir
Copy link
Member

amrbashir commented Dec 20, 2023

This will be support in v2 in tauri-plugin-http, see tauri-apps/plugins-workspace#824

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 📬Proposal
Development

No branches or pull requests

8 participants