Skip to content

Commit

Permalink
Add api module with download_to method
Browse files Browse the repository at this point in the history
Use the `ureq` crate for simple synchronous requests, but keep it
encapsulated so we can replace it later if need be. Create an agent that
supports proxies and require HTTPS for all requests. Use it in the
`download_to` method, but if the API base URL has a `file` schema, skip
the ureq agent and copy the file directly. This will be useful for
working with `rsync`d mirrors.

Add variants to the BuildError enum for IO, URL parsing and formatting,
and HTTP request errors from ureq. Box ureq errors because otherwise
they're far to big, and [clippy complains] about the error size. Make a custom
File error to improve IO errors to include the action attempted and relevant
file name or names.

Use `httpmock` to test the handling of `http:` URLs, and `sha2` & `tempfile`
to test `file:` URLs.

While at it, exclude `Cargo.lock` from `git diff`; it's just too verbose
and distracting. Also use string comparison for some error tests in
`src/tests.rs`.

  [clippy complains]: https://rust-lang.github.io/rust-clippy/master/index.html#result_large_errclippyClick
  • Loading branch information
theory committed Nov 6, 2024
1 parent fb8114c commit 7434659
Show file tree
Hide file tree
Showing 9 changed files with 1,598 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Cargo.lock -diff
Loading

0 comments on commit 7434659

Please sign in to comment.