mirror of
https://github.com/jht5945/buildj.git
synced 2025-12-27 09:20:03 +08:00
ref print_*
This commit is contained in:
14
src/http.rs
14
src/http.rs
@@ -4,8 +4,8 @@ use rust_util::{
|
||||
XResult,
|
||||
util_io::copy_io,
|
||||
util_msg::{
|
||||
print_message,
|
||||
MessageType,
|
||||
print_debug,
|
||||
print_warn,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -13,7 +13,7 @@ use super::misc::VERBOSE;
|
||||
|
||||
pub fn download_url(url: &str, dest: &mut File) -> XResult<()> {
|
||||
if *VERBOSE {
|
||||
print_message(MessageType::DEBUG, &format!("Start download URL: {}", url));
|
||||
print_debug(&format!("Start download URL: {}", url));
|
||||
}
|
||||
let mut response = reqwest::get(url)?;
|
||||
let header_content_length: i64 = match response.headers().get("content-length") {
|
||||
@@ -21,20 +21,20 @@ pub fn download_url(url: &str, dest: &mut File) -> XResult<()> {
|
||||
Some(len_value) => {
|
||||
let len_str = match len_value.to_str() {
|
||||
Ok(len_str) => len_str, Err(err) => {
|
||||
print_message(MessageType::WARN, &format!("Get content length for {:?}, error: {}", len_value, err));
|
||||
print_warn(&format!("Get content length for {:?}, error: {}", len_value, err));
|
||||
"-1"
|
||||
},
|
||||
};
|
||||
match len_str.parse::<i64>() {
|
||||
Ok(len) => len, Err(err) => {
|
||||
print_message(MessageType::WARN, &format!("Get content length for {:?}, error: {}", len_value, err));
|
||||
print_warn(&format!("Get content length for {:?}, error: {}", len_value, err));
|
||||
-1
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
if *VERBOSE {
|
||||
print_message(MessageType::DEBUG, &format!("Content-Length: {}", header_content_length));
|
||||
print_debug(&format!("Content-Length: {}", header_content_length));
|
||||
}
|
||||
copy_io(&mut response, dest, header_content_length)?;
|
||||
Ok(())
|
||||
@@ -42,7 +42,7 @@ pub fn download_url(url: &str, dest: &mut File) -> XResult<()> {
|
||||
|
||||
pub fn get_url_content(url: &str) -> XResult<String> {
|
||||
if *VERBOSE {
|
||||
print_message(MessageType::DEBUG, &format!("Get URL: {}", url));
|
||||
print_debug(&format!("Get URL: {}", url));
|
||||
}
|
||||
Ok(reqwest::get(url)?.text()?)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user