forked from divviup/prio-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
facilitator: refactor manifest fetching. (#207)
This adds a new get_url function that wraps ureq gets, turning ureq's synthetic_errors into Results, and using anyhow to add context about which URL failed. This also changes the manifest reader functions to take a slice of bytes instead of a reader.
- Loading branch information
Showing
6 changed files
with
84 additions
and
78 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use anyhow::{anyhow, Context, Result}; | ||
|
||
pub(crate) fn get_url(url: &str) -> Result<String> { | ||
let resp = ureq::get(url) | ||
// By default, ureq will wait forever to connect or | ||
// read. | ||
.timeout_connect(10_000) // ten seconds | ||
.timeout_read(10_000) // ten seconds | ||
.call(); | ||
if resp.synthetic_error().is_some() { | ||
Err(anyhow!( | ||
"fetching {}: {}", | ||
url, | ||
resp.into_synthetic_error().unwrap() | ||
)) | ||
} else if !resp.ok() { | ||
Err(anyhow!("fetching {}: status {}", url, resp.status())) | ||
} else { | ||
resp.into_string() | ||
.context(format!("reading body of {}", url)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters