-
Notifications
You must be signed in to change notification settings - Fork 177
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
Allow setting custom agent when converting from http
crate types
#735
Conversation
raw_header.extend(value.as_bytes()); | ||
let header = HeaderLine::from(raw_header).into_header().unwrap(); | ||
/// Converts an [`http::request::Builder`] into a [`Request`] with a custom [`Agent`]. | ||
pub fn convert_from_http_builder_with_agent(value: http::request::Builder, agent: crate::Agent) -> Request { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agent
is used only for the &self
request
call, so maybe take an &crate::Agent
here?
raw_header.extend(b": "); | ||
raw_header.extend(value.as_bytes()); | ||
/// Converts a [`http::request::Parts`] into a [`Request`] with a custom [`Agent`]. | ||
pub fn convert_from_http_parts_with_agent(value: http::request::Parts, agent: crate::Agent) -> Request { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here regarding &crate::Agent
.
raw_header.extend(value.as_bytes()); | ||
let header = HeaderLine::from(raw_header).into_header().unwrap(); | ||
/// Converts an [`http::request::Builder`] into a [`Request`] with a custom [`Agent`]. | ||
pub fn convert_from_http_builder_with_agent(value: http::request::Builder, agent: crate::Agent) -> Request { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this (and the from parts variant) should be an associated function on either Agent
or Request
? I.e.: agent.request_builder(builder)
, or Request::from_builder(builder)
and Request::from_builder_with_agent(builder, agent)
.
I think the cleaner way to do this would be with an extension trait. I.e. pub trait HttpTraitInterop {
fn to_ureq_with_agent(agent: Agent) -> ureq::Request;
} which we then implement for |
Closing since we are moving to 3.x. This might be solved since ureq 3.x is http crate based. |
I encountered a case where we needed to support custom ssl certificates as well as convert between the http crate as ureq. Because the conversion routines call into
crate::agent
directly this isn't possible. This PR adds helpers so I can do that, however, I'm not sure they're up to the standard of howureq
would do these things, so I'd love some pointers to help clean up this PR.