Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add api module with download_to method #3

Merged
merged 1 commit into from
Nov 14, 2024
Merged

Add api module with download_to method #3

merged 1 commit into from
Nov 14, 2024

Conversation

theory
Copy link
Member

@theory theory commented Nov 6, 2024

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 rsyncd 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.

@theory theory added the enhancement New feature or request label Nov 6, 2024
@theory theory requested a review from vrmiguel November 6, 2024 20:46
@theory theory self-assigned this Nov 6, 2024
@theory theory force-pushed the download branch 5 times, most recently from f006986 to 7434659 Compare November 8, 2024 21:09
.join("pair-0.1.7.zip");

// Start a lightweight mock server.
let server = MockServer::start();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Didn't know about this one. I used to use mockito a while back

src/error/mod.rs Outdated
@@ -11,4 +12,30 @@ pub enum BuildError {
/// Unknown pipeline error.
#[error("unknown build pipeline `{0}`")]
UnknownPipeline(String),

/// IO rror.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bah, fixed in b0f261a, thanks.

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
@theory theory merged commit b0f261a into main Nov 14, 2024
12 checks passed
@theory theory deleted the download branch November 14, 2024 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants