mirror of
https://github.com/yuzu-emu/liftinstall.git
synced 2024-12-23 05:35:34 +00:00
Use HTTP client with timeout
This commit is contained in:
parent
1578c4e284
commit
e3047c1bc9
19
src/http.rs
19
src/http.rs
|
@ -4,14 +4,22 @@
|
|||
|
||||
use hyper::header::ContentLength;
|
||||
|
||||
use reqwest;
|
||||
|
||||
use std::io::Read;
|
||||
use std::time::Duration;
|
||||
|
||||
use reqwest::Client;
|
||||
|
||||
/// Builds a customised HTTP client.
|
||||
pub fn build_client() -> Result<Client, String> {
|
||||
Client::builder()
|
||||
.timeout(Duration::from_secs(5))
|
||||
.build()
|
||||
.map_err(|x| format!("Unable to build cient: {:?}", x))
|
||||
}
|
||||
|
||||
/// Downloads a text file from the specified URL.
|
||||
pub fn download_text(url: &str) -> Result<String, String> {
|
||||
// TODO: Decrease check time
|
||||
let mut client = match reqwest::get(url) {
|
||||
let mut client = match build_client()?.get(url).send() {
|
||||
Ok(v) => v,
|
||||
Err(v) => return Err(format!("Failed to GET resource: {:?}", v)),
|
||||
};
|
||||
|
@ -26,8 +34,7 @@ pub fn stream_file<F>(url: &str, mut callback: F) -> Result<(), String>
|
|||
where
|
||||
F: FnMut(Vec<u8>, u64) -> (),
|
||||
{
|
||||
// TODO: Decrease check time
|
||||
let mut client = match reqwest::get(url) {
|
||||
let mut client = match build_client()?.get(url).send() {
|
||||
Ok(v) => v,
|
||||
Err(v) => return Err(format!("Failed to GET resource: {:?}", v)),
|
||||
};
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
//!
|
||||
//! Contains the Github API implementation of a release source.
|
||||
|
||||
use reqwest;
|
||||
use reqwest::header::UserAgent;
|
||||
use reqwest::StatusCode;
|
||||
|
||||
|
@ -10,6 +9,8 @@ use serde_json;
|
|||
|
||||
use sources::types::*;
|
||||
|
||||
use http::build_client;
|
||||
|
||||
pub struct GithubReleases {}
|
||||
|
||||
/// The configuration for this release.
|
||||
|
@ -35,7 +36,7 @@ impl ReleaseSource for GithubReleases {
|
|||
let mut results: Vec<Release> = Vec::new();
|
||||
|
||||
// Build the HTTP client up
|
||||
let client = reqwest::Client::new();
|
||||
let client = build_client()?;
|
||||
let mut response = client
|
||||
.get(&format!(
|
||||
"https://api.github.com/repos/{}/releases",
|
||||
|
|
Loading…
Reference in a new issue