mirror of
https://github.com/TeamPiped/reqwest4j.git
synced 2024-08-14 23:54:39 +00:00
Add some vm panic protection for non UTF-8 URLs.
This commit is contained in:
parent
574c384bf1
commit
35653a4832
2 changed files with 11 additions and 3 deletions
|
@ -43,7 +43,7 @@ signing {
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'rocks.kavin'
|
group = 'rocks.kavin'
|
||||||
version = '1.0'
|
version = '1.0.1'
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ use lazy_static::lazy_static;
|
||||||
use reqwest::{Client, Method, Url};
|
use reqwest::{Client, Method, Url};
|
||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
|
|
||||||
|
|
||||||
pub fn add(left: usize, right: usize) -> usize {
|
pub fn add(left: usize, right: usize) -> usize {
|
||||||
left + right
|
left + right
|
||||||
}
|
}
|
||||||
|
@ -32,7 +31,16 @@ pub extern "system" fn Java_rocks_kavin_reqwest4j_ReqwestUtils_fetch(
|
||||||
|
|
||||||
// set method, url, body, headers
|
// set method, url, body, headers
|
||||||
let method = Method::from_bytes(env.get_string(method).unwrap().to_bytes()).unwrap();
|
let method = Method::from_bytes(env.get_string(method).unwrap().to_bytes()).unwrap();
|
||||||
let url = Url::parse(&env.get_string(url).unwrap().to_str().unwrap()).unwrap();
|
|
||||||
|
let url = &env.get_string(url).unwrap();
|
||||||
|
let url = url.to_str();
|
||||||
|
|
||||||
|
if url.is_err() {
|
||||||
|
env.throw_new("java/lang/IllegalArgumentException", "Invalid URL provided, couldn't get string as UTF-8").unwrap();
|
||||||
|
return JObject::null().into_raw();
|
||||||
|
}
|
||||||
|
|
||||||
|
let url = Url::parse(url.unwrap()).unwrap();
|
||||||
let body = env.convert_byte_array(body).unwrap_or_default();
|
let body = env.convert_byte_array(body).unwrap_or_default();
|
||||||
let headers: JMap = JMap::from_env(&env, headers).unwrap();
|
let headers: JMap = JMap::from_env(&env, headers).unwrap();
|
||||||
let headers = headers.iter().unwrap().fold(HashMap::new(), |mut headers, (key, value)| {
|
let headers = headers.iter().unwrap().fold(HashMap::new(), |mut headers, (key, value)| {
|
||||||
|
|
Loading…
Reference in a new issue