Closed Ch00k closed 3 years ago
There are no special mechanisms in place for file upload yet. If expect_body
is too limiting and if you don't use httpmock
in standalone mode you can try to use the generic matcher function like this:
.expect_match(|req: MockServerRequest| { req.body.as_ref().unwrap().eq("test") })
where test
is the file content in string representation. It is not a closure at this time though but a simple function.
There is also an example here: https://github.com/alexliesenfeld/httpmock/blob/master/tests/request_matcher_tests.rs#L40
A PR for this is very welcome 😃.
I also tried this, and it works:
let mock_server = MockServer::start();
Mock::new()
.expect_method(Method::POST)
.expect_path("/foo")
.expect_body("bar")
.create_on(&mock_server);
let client = reqwest::blocking::Client::new();
client
.post(&mock_server.url("/foo"))
.body("bar".as_bytes())
.send()
.unwrap();
@Ch00k Is this still an issue?
No, sorry, I forgot to close it :)
Is there any way I can use
Mock.expect_body
with binary data (e.g. when I send POST request for a file upload)?