LukeMathWalker / LukeMathWalker/wiremock-rs

Single value header gets parsed as Vec

Open
#143 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
799
Forks
91
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the reproduction in src/main.rs from the linked repository and compare the single-value header matcher with the headers workaround. Trace the header matcher entry point used by Mock::given(header(...)). Done means a header value containing a comma matches the request as one value, with regression coverage for the reported case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.