-
Notifications
You must be signed in to change notification settings - Fork 519
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #542 from amazonlinux/updog-whats
updog: Add support for query parameters in TUF requests
- Loading branch information
Showing
5 changed files
with
70 additions
and
10 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
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,45 @@ | ||
use std::cell::{BorrowMutError, RefCell}; | ||
use tough::{HttpTransport, Repository, Transport}; | ||
use url::Url; | ||
|
||
#[derive(Debug)] | ||
#[allow(clippy::module_name_repetitions)] | ||
pub struct HttpQueryTransport { | ||
pub inner: HttpTransport, | ||
parameters: RefCell<Vec<(String, String)>>, | ||
} | ||
|
||
impl HttpQueryTransport { | ||
pub fn new() -> Self { | ||
Self { | ||
inner: HttpTransport::new(), | ||
parameters: RefCell::new(vec![]), | ||
} | ||
} | ||
|
||
/// Try to borrow a mutable reference to parameters; returns an error if | ||
/// a borrow is already active | ||
pub fn queries_get_mut( | ||
&self, | ||
) -> Result<std::cell::RefMut<'_, Vec<(String, String)>>, BorrowMutError> { | ||
self.parameters.try_borrow_mut() | ||
} | ||
|
||
fn set_query_string(&self, mut url: Url) -> Url { | ||
for (key, val) in self.parameters.borrow().iter() { | ||
url.query_pairs_mut().append_pair(&key, &val); | ||
} | ||
url | ||
} | ||
} | ||
|
||
pub type HttpQueryRepo<'a> = Repository<'a, HttpQueryTransport>; | ||
|
||
impl Transport for HttpQueryTransport { | ||
type Stream = reqwest::Response; | ||
type Error = reqwest::Error; | ||
|
||
fn fetch(&self, url: Url) -> Result<Self::Stream, Self::Error> { | ||
self.inner.fetch(self.set_query_string(url)) | ||
} | ||
} |