Giter VIP home page Giter VIP logo

reqwest_cookie_store's Introduction

Documentation

reqwest_cookie_store provides implementations of reqwest::cookie::CookieStore for cookie_store.

Example

The following example demonstrates loading a cookie_store::CookieStore (re-exported in this crate) from disk, and using it within a CookieStoreMutex. It then makes a series of requests, examining and modifying the contents of the underlying cookie_store::CookieStore in between.

// Load an existing set of cookies, serialized as json
let cookie_store = {
  let file = std::fs::File::open("cookies.json")
      .map(std::io::BufReader::new)
      .unwrap();
  // use re-exported version of `CookieStore` for crate compatibility
  reqwest_cookie_store::CookieStore::load_json(file).unwrap()
};
let cookie_store = reqwest_cookie_store::CookieStoreMutex::new(cookie_store);
let cookie_store = std::sync::Arc::new(cookie_store);
{
  // Examine initial contents
  println!("initial load");
  let store = cookie_store.lock().unwrap();
  for c in store.iter_any() {
    println!("{:?}", c);
  }
}

// Build a `reqwest` Client, providing the deserialized store
let client = reqwest::Client::builder()
    .cookie_provider(std::sync::Arc::clone(&cookie_store))
    .build()
    .unwrap();

// Make a sample request
client.get("https://google.com").send().await.unwrap();
{
  // Examine the contents of the store.
  println!("after google.com GET");
  let store = cookie_store.lock().unwrap();
  for c in store.iter_any() {
    println!("{:?}", c);
  }
}

// Make another request from another domain
println!("GET from msn");
client.get("https://msn.com").send().await.unwrap();
{
  // Examine the contents of the store.
  println!("after msn.com GET");
  let mut store = cookie_store.lock().unwrap();
  for c in store.iter_any() {
    println!("{:?}", c);
  }
  // Clear the store, and examine again
  store.clear();
  println!("after clear");
  for c in store.iter_any() {
    println!("{:?}", c);
  }
}

// Get some new cookies
client.get("https://google.com").send().await.unwrap();
{
  // Write store back to disk
  let mut writer = std::fs::File::create("cookies2.json")
      .map(std::io::BufWriter::new)
      .unwrap();
  let store = cookie_store.lock().unwrap();
  store.save_json(&mut writer).unwrap();
}

reqwest_cookie_store's People

Contributors

10ne1 avatar aknarts avatar c0d3-m4513r avatar nathaniel-daniel avatar pfernie avatar pxp9 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

reqwest_cookie_store's Issues

Publish version 0.2.0?

I see that the git repository has been updated to version 0.2.0 and is compatible with cookie_store 0.15, but this new version has not yet been published to crates.io. Is it ready to publish?

cookie.json is empty when write to disk

Everything works as expected but when i write cookies to disk, it is empty.

let store = cookie_store.lock().unwrap();

    for c in store.iter_any() {
        println!("{:?}", c);
    }
store.save_json(&mut writer).unwrap();

It write cookie right with println! but somehow its empty on disk when save_json write it.

cookie_store 0.16 breaks reqwest_cookie_store::CookieStoreMutex::new

Using pretty much the code from the readme fails now

error[E0308]: mismatched types
  --> src/lib.rs:94:72
   |
94 |         let cookie_store = reqwest_cookie_store::CookieStoreMutex::new(store);
   |                                                                        ^^^^^ expected struct `cookie_store::cookie_store::CookieStore`, found struct `cookie_store::CookieStore`
   |
   = note: perhaps two different versions of crate `cookie_store` are being used?

Please update the Cargo.toml to use the proper version of the other crate

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.