Closed sbohrer closed 3 years ago
Hmm, interesting. I'll look into it in the next few days. Thanks for reporting!
Unfortunately I could not reproduce this, neither in tests nor in standalone mode. On a first sight, the warning comes from this code line though. Could you please give me a little more information about the context of how you use httpmock in this particular example? What do you use for logging in your tests?
Cargo.toml:
[package]
name = "httpmock-examp"
version = "0.1.0"
authors = ["Shawn Bohrer <sbohrer@cloudflare.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
flexi_logger = "0.11"
httpmock = "0.5"
reqwest = { version = "0.10", features = ["json", "rustls-tls"] }
tokio = { version = "0.2", features = ["full"] }
src/main.rs:
use httpmock::MockServer;
#[tokio::main]
async fn main() {
flexi_logger::Logger::with_str("warn")
.start()
.expect("failed to create logger");
let server = MockServer::start_async().await;
server
.mock_async(|when, then| {
when.method("GET").path_contains("/hello");
then.body("Hello").status(200);
})
.await;
let body = reqwest::get(&server.url("/hello"))
.await
.unwrap()
.text()
.await
.unwrap();
println!("body: {}", body);
}
cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.10s
Running `target/debug/httpmock-examp`
WARN [httpmock::server::matchers::targets] Cannot parse json value: EOF while parsing a value at line 1 column 0
WARN [httpmock::server::matchers::targets] Cannot parse json value: EOF while parsing a value at line 1 column 0
body: Hello
@sbohrer This issue should be fixed in version 0.5.6.
Thanks!
If I set up a mock for a GET request:
Then send a GET using reqwest:
I see:
WARN httpmock::server::matchers::targets] Cannot parse json value: EOF while parsing a value at line 1 column 0
It appears this is because it thinks there is a body on the GET request and tries to parse it has json. Everything appears to work as intended except for the warning prints.