Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single value header gets parsed as Vec #143

Open
muttleyxd opened this issue Apr 30, 2024 · 0 comments
Open

Single value header gets parsed as Vec #143

muttleyxd opened this issue Apr 30, 2024 · 0 comments

Comments

@muttleyxd
Copy link

muttleyxd commented Apr 30, 2024

I have encountered an interesting bug - trying to match a header value which contains a comma , results in incoming header value being parsed as Vec

What doesn't work, but I think it should

let mock_server = MockServer::start().await;

Mock::given(header("if-modified-since", "Sat, 02 Apr 2005 20:37:00 GMT")) // This is valid RFC2822
  .respond_with(ResponseTemplate::new(304))
  .expect(1)
  .mount(&mock_server)
  .await;

// This will return 404
let _result = reqwest::Client::new()
  .get(mock_server.uri())
  .header("if-modified-since", "Sat, 02 Apr 2005 20:37:00 GMT")
  .send()
  .await
  .unwrap()
  .error_for_status()
  .unwrap();

Workaround I found:

let mock_server = MockServer::start().await;

Mock::given(headers(
    "if-modified-since",
    vec!["Sat", "02 Apr 2005 20:37:00 GMT"],
  ))
  .respond_with(ResponseTemplate::new(304))
  .expect(1)
  .mount(&mock_server)
  .await;

// Returns 304
let _result = reqwest::Client::new()
    .get(mock_server.uri())
    .header("if-modified-since", "Sat, 02 Apr 2005 20:37:00 GMT")
    .send()
    .await
    .unwrap()
    .error_for_status()
    .unwrap();
}

I have prepared a repository with a test that reproduces the issue: https://github.com/muttleyxd/wiremock-header-matcher-bug/blob/master/src/main.rs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant