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

Allow setting custom agent when converting from http crate types #735

Closed
wants to merge 1 commit into from

Conversation

Jasper-Bekkers
Copy link

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 how ureq would do these things, so I'd love some pointers to help clean up this PR.

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 {

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 {

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 {

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

@algesten
Copy link
Owner

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 http::Request/Builder etc

@algesten
Copy link
Owner

Closing since we are moving to 3.x. This might be solved since ureq 3.x is http crate based.

@algesten algesten closed this Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants