~rjframe/surf-vcr

02fcf3c40bf80b63c26d9049afb3c3c62ba768fd — Ryan Frame 2 months ago 57a6954 main v0.2.0
Update documentation for release
3 files changed, 31 insertions(+), 8 deletions(-)

M Cargo.toml
M README.md
M src/lib.rs
M Cargo.toml => Cargo.toml +1 -1
@@ 1,6 1,6 @@
[package]
name = "surf-vcr"
version = "0.1.2"
version = "0.2.0"
edition = "2018"
authors = ["Ryan Frame <code@ryanjframe.com>"]
license = "MPL-2.0"

M README.md => README.md +5 -7
@@ 42,8 42,7 @@ Or add it to your `Cargo.toml` file manually:

```toml
[dev-dependencies]

surf-vcr = "0.1.1"
surf-vcr = "0.2.0"
```




@@ 117,19 116,18 @@ made, intercept it, and return the saved response.

### Modify Recorded Content

It is possible to modify data before writing to your cassette files. This is useful while working with sensitive or dynamic data.
You can modify data before writing to your cassette files. This is useful while
working with sensitive or dynamic data.

```rust
VcrMiddleware::new(VcrMode::Record, path).await?
    .with_modify_request(|req| {
        req
            .headers
        req.headers
            .entry("session-key".into())
            .and_modify(|val| *val = vec!["...(erased)...".into()]);
    })
    .with_modify_response(|res| {
        res
            .headers
        res.headers
            .entry("Set-Cookie".into())
            .and_modify(|val| *val = vec!["...(erased)...".into()]);
    });

M src/lib.rs => src/lib.rs +25 -0
@@ 85,6 85,23 @@
//!     assert!(widgets.is_err());
//! }
//! ```
//!
//! You can also hide sensitive information before saving the data to your
//! cassettes:
//!
//! ```ignore
//! VcrMiddleware::new(VcrMode::Record, path).await?
//!     .with_modify_request(|req| {
//!         req.headers
//!             .entry("session-key".into())
//!             .and_modify(|val| *val = vec!["...(erased)...".into()]);
//!     })
//!     .with_modify_response(|res| {
//!         res.headers
//!             .entry("Set-Cookie".into())
//!             .and_modify(|val| *val = vec!["...(erased)...".into()]);
//!     });
//! ```


use std::{


@@ 285,6 302,7 @@ impl VcrMiddleware {
        })
    }

    /// Register a modifier function to alter requests before saving to disk.
    pub fn with_modify_request<F>(mut self, modifier: F) -> Self
        where F: Fn(&mut VcrRequest) + Send + Sync + 'static
    {


@@ 292,6 310,7 @@ impl VcrMiddleware {
        self
    }

    /// Register a modifier function to alter responses before saving to disk.
    pub fn with_modify_response<F>(mut self, modifier: F) -> Self
        where F: Fn(&mut VcrResponse) + Send + Sync + 'static
    {


@@ 327,6 346,9 @@ pub enum VcrMode {
}

/// Request to be recorded in cassettes.
///
/// You are unlikely to need to work with this directly except via
/// [VcrMiddleware::with_modify_request].
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct VcrRequest {
    pub method: Method,


@@ 392,6 414,9 @@ impl From<VcrRequest> for Request {
}

/// Response to be recorded in cassettes.
///
/// You are unlikely to need to work with this directly except via
/// [VcrMiddleware::with_modify_response].
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct VcrResponse {
    pub status: StatusCode,