Jacob Hoffman-Andrews 703ca41960 Push mutexes down into pool and cookie store. (#193)
Previously, Agent stored most of its state in one big
Arc<Mutex<AgentState>>. This separates the Arc from the Mutexes.
Now, Agent is a thin wrapper around an Arc<AgentState>. The individual
components that need locking, ConnectionPool and CookieStore, now are
responsible for their own locking.

There were a couple of reasons for this. Internal components that needed
an Agent were often instead carrying around an Arc<Mutex<AgentState>>.
This felt like the components were too intertwined: those other
components shouldn't have to care quite so much about how Agent is
implemented. Also, this led to compromises of convenience: the Proxy on
Agent wound up stored inside the `Arc<Mutex<AgentState>>` even though it
didn't need locking. It was more convenient that way because that was
what Request and Unit had access too.

The other reason to push things down like this is that it can reduce
lock contention. Mutations to the cookie store don't need to lock the
connection pool, and vice versa. This was a secondary concern, since I
haven't actually profiled these things and found them to be a problem,
but it's a happy result of the refactoring.

Now all the components outside of Agent take an Agent instead of
AgentState.

In the process I removed `Agent.cookie()`. Its API was hard to use
correctly, since it didn't distinguish between cookies on different
hosts. And it would have required updates as part of this refactoring.
I'm open to reinstating some similar functionality with a refreshed API.

I kept `Agent.set_cookie`, but updated its method signature to take a
URL as well as a cookie.

Many of ConnectionPool's methods went from `&mut self` to `&self`,
because ConnectionPool is now using interior mutability.
2020-10-20 00:03:45 -07:00
2020-10-03 20:47:35 -07:00
2020-10-18 11:30:38 +02:00
2020-10-06 10:05:48 +02:00
2020-01-26 23:18:22 +01:00
2020-01-26 23:18:22 +01:00
2020-10-17 17:59:29 -07:00
2020-10-19 01:18:56 +02:00
2020-10-03 20:47:35 -07:00

ureq

CratesIO Documentation

Minimal request library in rust.

Usage

// sync post request of some json.
// requires feature:
// `ureq = { version = "*", features = ["json"] }`
let resp = ureq::post("https://myapi.example.com/ingest")
    .set("X-My-Header", "Secret")
    .send_json(serde_json::json!({
        "name": "martin",
        "rust": true
    }))?;

// .ok() tells if response is 200-299.
if resp.ok() {
  println!("success: {}", resp.into_string()?);
} else {
  println!("error {}: {}", resp.status(), resp.into_string()?);
}

About 1.0.0

This crate is now 1.x.x. It signifies there will be no more breaking API changes (for better or worse). I personally use this code in production system reading data from AWS. Whether the quality is good enough for other use cases is a "YMMV".

ureq's future

I asked for feedback on ureq's future direction and came to the conclusion that there's enough interest in a simple blocking http client to keep it going. Another motivation is that I use it extensively for my own work, to talk to S3.

I'll keep maintaining ureq. I will try to keep dependencies somewhat fresh and try to address bad bugs. I will however not personally implement new features in ureq, but I do welcome PR with open arms.

The code base is extremely simple, one might even call naive. It's a good project to hack on as first learning experience in Rust. I will uphold some base line of code hygiene, but won't block a PR due to something being a bit inelegant.

Features

To enable a minimal dependency tree, some features are off by default. You can control them when including ureq as a dependency.

    ureq = { version = "*", features = ["json", "charset"] }
  • tls enables https. This is enabled by default.
  • native-tls enables https using the native-tls crate. NB: To make this work you currently need to use default-features: false to disable tls. We plan on fixing that.
  • json enables response.into_json() and request.send_json() via serde_json.
  • charset enables interpreting the charset part of Content-Type: text/plain; charset=iso-8859-1. Without this, the library defaults to rust's built in utf-8.

Motivation

  • Minimal dependency tree
  • Obvious API
  • Blocking API
  • Convenience over correctness
  • No use of unsafe

This library tries to provide a convenient request library with a minimal dependency tree and an obvious API. It is inspired by libraries like superagent and fetch API.

Sync forever

This library uses blocking socket reads and writes. When it was created, there wasn't any async/await support in rust, and for my own purposes, blocking IO was fine. At this point, one good reason to keep this library going is that it is blocking (the other is that it does not use unsafe).

TODO

  • Forms with application/x-www-form-urlencoded
  • multipart/form-data
  • Expect 100-continue
  • Use rustls when ring with versioned asm symbols is released. (PR is not resolved, but most implementations have settled on 0.13)

License

Copyright (c) 2019 Martin Algesten

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Description
No description provided
Readme 1.3 MiB
Languages
Rust 99.9%
Shell 0.1%