mirror of
https://github.com/TeamPiped/reqwest4j.git
synced 2024-12-12 21:30:38 +05:30
Add support set basic proxy authentication.
This commit is contained in:
parent
31bfff42e3
commit
2c81e10652
@ -15,6 +15,8 @@ pub extern "system" fn Java_rocks_kavin_reqwest4j_ReqwestUtils_init(
|
|||||||
mut env: JNIEnv,
|
mut env: JNIEnv,
|
||||||
_: JClass,
|
_: JClass,
|
||||||
proxy: JString,
|
proxy: JString,
|
||||||
|
user: JString,
|
||||||
|
pass: JString,
|
||||||
) {
|
) {
|
||||||
let builder = Client::builder()
|
let builder = Client::builder()
|
||||||
.user_agent("Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Firefox/102.0");
|
.user_agent("Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Firefox/102.0");
|
||||||
@ -23,6 +25,15 @@ pub extern "system" fn Java_rocks_kavin_reqwest4j_ReqwestUtils_init(
|
|||||||
Ok(proxy) => {
|
Ok(proxy) => {
|
||||||
let proxy = proxy.to_str().unwrap();
|
let proxy = proxy.to_str().unwrap();
|
||||||
let proxy = reqwest::Proxy::all(proxy).unwrap();
|
let proxy = reqwest::Proxy::all(proxy).unwrap();
|
||||||
|
let proxy = match env.get_string(&user) {
|
||||||
|
Ok(user) => {
|
||||||
|
let user = user.to_str().unwrap();
|
||||||
|
let pass = env.get_string(&pass).unwrap();
|
||||||
|
let pass = pass.to_str().unwrap();
|
||||||
|
proxy.basic_auth(user, pass)
|
||||||
|
}
|
||||||
|
Err(_) => proxy,
|
||||||
|
};
|
||||||
builder.proxy(proxy)
|
builder.proxy(proxy)
|
||||||
}
|
}
|
||||||
Err(_) => builder,
|
Err(_) => builder,
|
||||||
|
@ -53,7 +53,7 @@ public class ReqwestUtils {
|
|||||||
System.load(nativeFile.getAbsolutePath());
|
System.load(nativeFile.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static native void init(String proxy);
|
public static native void init(String proxy, String user, String pass);
|
||||||
|
|
||||||
public static native CompletableFuture<Response> fetch(String url, String method, byte[] body,
|
public static native CompletableFuture<Response> fetch(String url, String method, byte[] body,
|
||||||
Map<String, String> headers);
|
Map<String, String> headers);
|
||||||
|
Loading…
Reference in New Issue
Block a user