-
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
ureq 3.x #762
ureq 3.x #762
Conversation
a4233f3
to
1b9cb3b
Compare
For a while I was considering the main API entry point would be taking the request pub fn run(request: &Request<impl IntoBody>) -> Result<Response<RecvBody>, Error> { ... } However pub fn run(request: Request<impl IntoBody>) -> Result<Response<RecvBody>, Error> { ... } |
Just wanted to comment to say that I am very excited about the potential to use ureq with WASM! I managed to make ureq 2.x compile for WASM with some conditional compilation of rustls things, but am currently facing implementing further conditional compilation of TCPStream and some other things to make requests execute successfully. This rewrite was a great idea and will be really useful for my projects. |
@amkillam I haven't done any WASM myself, so I don't know what do's and dont's there are. I'm not sure I can go full I just tried to compile this branch with If I add that to the CI, are there more lints/things to check for? |
If compilation works then it should be most of the way there. Could you provide an example of how ureq usage would change in 3.x? I can try to make a working example of ureq usage in WASM based on that, and share my results after. |
Also I'm not totally sure about tests specific to WASM yet, but I think once I've (hopefully) created a working example of usage in WASM, I'll be in a better position to comment or maybe contribute if you'd like! |
I will pick you up on that, but it's a bit too early still. I can't even make ureq 3.x do a regular request just yet. Hopefully in a couple of days. |
I really really think the MSRV policy should at least be relaxed and communicated clearly with a major version bump. My personal opinion is that users shouldn't be relying on this in the first place but such is life. I'm not saying we should bump MSRV anytime a new Rust version is released but allow for some modernization when it makes sense. |
The problem is developer environments installed via Linux (or similar) package managers instead of rustup. They tend to have a much slower upgrade cadence. I want ureq to be available to as many users as possible, and I personally don't think the code get that much worse by not having "modern" constructs like let-else. You're right about once cell – there we can avoid a dependency. So far I've managed to avoid using it, we'll see how that goes when I get more into the tests. I've been forced to bump MSRV to 1.63 because rustls bumped, so right now I'm leaning towards 1.63. But nothing is set in stone. |
That's valid. Just as an example, the creator of once_cell supports at least the previous eight Rust versions which is roughly ~1 year behind current. To me, that seems reasonable. Also as an aside, compatibility for crates and Rust versions is tracked here if you are interested: https://lib.rs/stats#rustc |
This comment was marked as outdated.
This comment was marked as outdated.
Actually. I need TLS also for SOCKS. |
I've been debating in my head how to think about Send/Sync. ureq 2.x is very liberal, Agent, Request and Response are all thread safe. In ureq 3.x, I gone from thinking "let's just stay on the thread" (i.e. nothing is Send/Sync), to thinking, that maybe some parts should be. One core idea is to avoid allocations and thus not require ownership of any request body – that can be orthogonal with being Send/Sync. However I think we can get around it. This is how the types map from ureq 2.x -> 3.x.
ureq 3.x deliberately drops the type names pub fn run(&self, request: http::Request<impl AsBody>) -> Result<http::Response<RecvBody>, Error> { This lives side by side with the existing ureq2 API. These are equivalent: New http-crate centric API: let data = vec![0_u8, 1, 2, 3, 4];
let request = http::Request::post("https://yaz").body(&data).unwrap();
let response = ureq::run(request).unwrap(); Old ureq2 API. Notice that let data = vec![0_u8, 1, 2, 3, 4];
let response = ureq::post("https://yaz").send_bytes(&data).unwrap();
|
Considering building out a TLS API in ureq3.x to not be in the situation we have in #765 Instead of exposing/re-exporting rustls config (or native-tls), we would abstract over both. The initial abstraction would need support a reasonable amount of minimal config:
Even if we default to rustls, native-tls might be a better starting point for looking at which config options to include, since rustls can do more than native-tls. https://docs.rs/native-tls/0.2.12/native_tls/struct.TlsConnectorBuilder.html |
f365d90
to
965fdff
Compare
Got TLS working with both rustls and native-tls. For now I decided to not use the webpki-roots crate instead opting for using Question is how many ureq users want the webpki-roots instead? |
@amkillam i think we're at a place where we can try webasm now. What I'm not clear on is whether webasm can give me a TCP socket style interface and if TLS should be in-or-outside the scope ureq. Let me explain what we got and see if this is a good starting point for tinkering.
The
Let's take a concrete example. Let's say webasm transport does not need an explicit resolving, instead you give it some combo (hostname, port, is_tls) – then we can write a dummy Resolver that does nothing and a corresponding Transport opening the connection. If I remove all default features, it compiles on wasm32-unknown-unknown. If we need to bring in some feature like rustls, we can maybe make it compole through feature flags – needs investigating. |
For unrelated reasons we've been thinking about extending If you were open to breaking symmetry between backends the rustls-platform-verifier crate is often the best choice for
I'm very out of the loop with wasm, but have heard folks say they've gotten rustls working there. Certainly you need In case it helps colour your decision for support |
That would be a most welcome feature indeed. In a previous life I hugely preferred
Looks great! Revocations support is nice, and using the OS-default verifiers probably means even better protection in case there are 0-day updates etc. I think it is worth breaking symmetry for, yes.
Interesting. I was hoping that by making the transport truly plug-in in ureq3.x this would open for these possibilities. But I'm not sure I'll tinker with it much myself until I have a real need. |
b55ed8f
to
6fc839c
Compare
With that last push, ureq 3.x is now feature complete in terms of feature flags. There are a couple of TODOs I want to deal with and I need to glance through the 2.x code to make sure there aren't functionality areas that I've forgotten about. Next up is porting all the tests over. |
In case it ends up being helpful I wanted to mention I finished implementing this. It ended up being a separate crate instead of an opt-in feature: https://crates.io/crates/webpki-root-certs |
5f2a503
to
01ee307
Compare
Moving this to the main branch with individual PRs now. |
This PR/branch is a complete, from the ground up rewrite of ureq. For Rust there clearly is a role for a sync, minimal dependency HTTP/1.1 client. The ureq 2.x code has gradually been iterated to its current state, but some early design decisions means we are struggling to make some changes we would like to have (such as being transport agnostic). While ureq's surface API is largely okay (with some warts), internally there is a lack of good separation of concerns and clear contracts between the parts of the library.
This PR starts from a complete clean slate, but the intention is to gradually bring back code from the 2.x branch where it makes sense to do so. Especially I'd like to bring back the majority of the tests to ensure backwards compatibility. The intention is also to preserve as much of the API surface as possible, only making changes in areas where there currently are clear problems (such as making unnecessary allocations). The intention is to also have a 1-1 feature parity with 2.x and the MSRV will not move much.
This PR/effort might not work out. I might discover things that are irreconcilable with the current ureq 2.x, or I might run out of steam to complete the project. There is also no timeline for completion, might take months, might take years. Ideally there are more people wanting to engage in the project – please talk to me here or send an email!
Here are some things I been thinking about fixing:
Please engage in discussion below if there are things I have omitted or ideas of where ureq could go!