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

使用代理软件squid支持https #2

Open
zhengxingjian opened this issue Jan 9, 2023 · 4 comments
Open

使用代理软件squid支持https #2

zhengxingjian opened this issue Jan 9, 2023 · 4 comments

Comments

@zhengxingjian
Copy link

zhengxingjian commented Jan 9, 2023

因为reqwest_wasi不支持https请求,原因可能是(加密算法移植不好实现,证书库验证不好实现等,而且发对aes加密效率还行,但对rsa非对称加密效率极低,2048位加密"hello word"需要最快13分钟[普通机器])。
但因为使用wasi是用wasmedge做faas实现,也就是轻量级业务,一般只要支持curd业务就行了,但生态毕竟有缺,一些基本功能不用wasi实现(rust x86平台依赖或操作系统依赖不好编译成wasi平台时),可以搭建基础常用功能,比如http正向代理软件,来实现https的请求。
首先安装,配置,启动squid(windows安装其它对应代理软件)。
注:squid的端口默认为3128,建议修改。

主要在这两行代码上

reqwest::Proxy::https("http://10.0.182.172:3128")
reqwest::Proxy::http("http://10.0.182.172:3128")

例子:对百度的https访问


pub async fn baidu() -> Result<Response<Body>, anyhow::Error> {
    // Some simple CLI args requirements...
    let url = "https://www.baidu.com/baidu?tn=monline_7_dg&ie=utf-8&wd=repository";

    let client = reqwest::Client::builder()
        .proxy(reqwest::Proxy::https("http://10.0.182.172:3128")?)
        .proxy(reqwest::Proxy::http("http://10.0.182.172:3128")?)
        .build()?;

    let body = client.get(url).send()
        .await?
        .text()
        .await?;

    println!("body = {:?}", body);
// let body="test".to_string();
    Ok(response_build(&body))
}

意义在于平台级只用搭一个代理软件来代理https流量访问,对于N个wasm镜像运行,很有作用(否则就需要对https整个实现wasi平台支持,不过发现rsa加密过程[公私密钥生成时间太长],所以放弃了)。

@juntao
Copy link
Member

juntao commented Jan 10, 2023

Thanks! Will add this to our docs. An alternative to this is to use the HTTPS plugin + the http_req_wasi crate for WasmEdge.

Crate: https://crates.io/crates/http_req_wasi
Source code: https://github.com/second-state/http_req
Example: https://github.com/second-state/http_req/blob/master/examples/get_https.rs

@juntao
Copy link
Member

juntao commented Jan 12, 2023

Need to install the plugin like the following. See https://github.com/second-state/http_req#build-and-run

# Download and extract the plugin
wget https://github.com/WasmEdge/WasmEdge/releases/download/0.11.1/WasmEdge-plugin-wasmedge_httpsreq-0.11.1-manylinux2014_x86_64.tar.gz
tar -xzf WasmEdge-plugin-wasmedge_httpsreq-0.11.1-manylinux2014_x86_64.tar.gz

# Install the plugin if your wasmedge is installed in ~/.wasmedge
cp libwasmedgePluginHttpsReq.so ~/.wasmedge/plugin/

# Install the plugin if your wasmedge is installed in /usr/local
cp libwasmedgePluginHttpsReq.so /usr/local/lib/wasmedge/

@zhengxingjian
Copy link
Author

Need to install the plugin like the following. See https://github.com/second-state/http_req#build-and-run

# Download and extract the plugin
wget https://github.com/WasmEdge/WasmEdge/releases/download/0.11.1/WasmEdge-plugin-wasmedge_httpsreq-0.11.1-manylinux2014_x86_64.tar.gz
tar -xzf WasmEdge-plugin-wasmedge_httpsreq-0.11.1-manylinux2014_x86_64.tar.gz

# Install the plugin if your wasmedge is installed in ~/.wasmedge
cp libwasmedgePluginHttpsReq.so ~/.wasmedge/plugin/

# Install the plugin if your wasmedge is installed in /usr/local
cp libwasmedgePluginHttpsReq.so /usr/local/lib/wasmedge/

看到了,还以为是没有开启 "wasmedge_ssl"特性。http_req_wasi = { version ="0.10.1", features =["wasmedge_ssl"]},希望能在docker镜像运行时上,直接集成上。

@juntao
Copy link
Member

juntao commented Jan 12, 2023

Yes. We are working on Docker integration for the plugins!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants