-
Notifications
You must be signed in to change notification settings - Fork 2
Use ureq instead of reqwest #8
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2dfbea0
Replace reqwest with ureq in git.rs, http.rs, ipfs.rs
oleksandrvoyager 711bc87
Add Accept header and refactor git.rs, http.rs, ipfs.rs with improved…
oleksandrvoyager dcd6308
Revert "Add Accept header and refactor git.rs, http.rs, ipfs.rs with …
oleksandrvoyager 7daf928
Refactor git.rs, http.rs, ipfs.rs with improved utils.rs structure
oleksandrvoyager 0df9436
Fix: conditionally compile utils.rs based on features that require ureq
oleksandrvoyager 15f1a2f
Add Accept header and open_with_config
oleksandrvoyager 1e0cae7
empty line
oleksandrvoyager 076dd90
refactor(ipfs): rename shadowed `url` variable to `gateway_url` for c…
oleksandrvoyager File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,25 +1,51 @@ | ||
| // This is free and unencumbered software released into the public domain. | ||
|
|
||
| use crate::{Read, Result, Url}; | ||
| use reqwest::{blocking::ClientBuilder, redirect}; | ||
| use crate::{Read, RequestConfig, Result, Url}; | ||
| use crate::schemes::request; | ||
|
|
||
| static USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")); | ||
|
|
||
| /// See: https://en.wikipedia.org/wiki/HTTP | ||
| /// See: https://en.wikipedia.org/wiki/HTTPS | ||
| /// Performs an HTTP or HTTPS GET request to fetch a file from a URL. | ||
| /// | ||
| /// # Arguments | ||
| /// * `url` - The URL to fetch (e.g., `http://example.com/file.txt` or `https://example.com/file.txt`). | ||
| /// * `secure` - Whether to use HTTPS (TLS) for the request. | ||
| /// | ||
| /// # Returns | ||
| /// A `Result` containing a boxed readable stream (`Box<dyn Read>`) on success, or an `Error` on failure. | ||
| /// | ||
| /// # References | ||
| /// - [HTTP Protocol](https://en.wikipedia.org/wiki/HTTP) | ||
| /// - [HTTPS Protocol](https://en.wikipedia.org/wiki/HTTPS) | ||
| pub fn open<'a, 'b>(url: &'a Url<'b>, secure: bool) -> Result<Box<dyn Read>> { | ||
| // See: https://docs.rs/reqwest/latest/reqwest/blocking/struct.ClientBuilder.html | ||
| let mut client = ClientBuilder::new() | ||
| .user_agent(USER_AGENT) | ||
| .redirect(redirect::Policy::default()); | ||
| // See: https://docs.rs/ureq/3.0.12/ureq/struct.Agent.html | ||
| let agent = request::new_agent(secure, None); | ||
|
|
||
| if secure { | ||
| client = client.https_only(true); | ||
| } | ||
| // See: https://docs.rs/ureq/3.0.12/ureq/struct.Agent.html#method.get | ||
| // See: https://docs.rs/ureq/3.0.12/ureq/struct.RequestBuilder.html#method.call | ||
| request::fetch(&agent, url.as_str()) | ||
| } | ||
|
|
||
| // See: https://docs.rs/reqwest/latest/reqwest/blocking/struct.Client.html#method.get | ||
| // See: https://docs.rs/reqwest/latest/reqwest/blocking/struct.RequestBuilder.html | ||
| let response = client.build()?.get(url.as_str()).send()?; | ||
| /// Performs an HTTP or HTTPS GET request to fetch a file from a URL with custom request configuration. | ||
| /// | ||
| /// # Arguments | ||
| /// * `url` - The URL to fetch (e.g., `http://example.com/file.txt` or `https://example.com/file.txt`). | ||
| /// * `secure` - Whether to use HTTPS (TLS) for the request. | ||
| /// * `config` - Custom request configuration, such as HTTP headers. | ||
| /// | ||
| /// # Returns | ||
| /// A `Result` containing a boxed readable stream (`Box<dyn Read>`) on success, or an `Error` on failure. | ||
| /// | ||
| /// # References | ||
| /// - [HTTP Protocol](https://en.wikipedia.org/wiki/HTTP) | ||
| /// - [HTTPS Protocol](https://en.wikipedia.org/wiki/HTTPS) | ||
| pub fn open_with_config<'a, 'b>( | ||
| url: &'a Url<'b>, | ||
| secure: bool, | ||
| config: RequestConfig | ||
| ) -> Result<Box<dyn Read>> { | ||
| // See: https://docs.rs/ureq/3.0.12/ureq/struct.Agent.html | ||
| let agent = request::new_agent(secure, None); | ||
|
|
||
| Ok(Box::new(response)) | ||
| // See: https://docs.rs/ureq/3.0.12/ureq/struct.Agent.html#method.get | ||
| // See: https://docs.rs/ureq/3.0.12/ureq/struct.RequestBuilder.html#method.call | ||
| request::fetch_with_config(&agent, url.as_str(), &config) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.