OpenFeign / OpenFeign/feign

feign-mock is too strict with request headers when matching requests

Open
#1,552 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted proposal
Dominant language
Java
Stars
9.8k
Forks
1.9k
Avg merge
1d 2h
Merged PRs (30d)
41

Description

I am using https://github.com/OpenFeign/feign/tree/master/mock to write unit tests. When one would want to match/verify request headers, the current implementation seems too strict as it checks for exact equality. Ideally, it should be matching a subset of the headers as there can be headers the tester doesn't care about or generated headers like Content-Length.

I know the workaround for this is to write a RequestInterceptor and do assertions there, but that is not ideal as it adds a lot of boilerplate code in tests. For each test, one needs to write a test-specific RequestInterceptor.

I would like to propose making the header matching in RequestKey.java#L171 match a subset of the headers instead of exact equality.

Bonus Request: match with RegEx

Contributor guide

Open the contributing guide

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 in mock/src/main/java/feign/mock/RequestKey.java at the header comparison around line 171. Review how request headers are matched and define done as allowing expected headers to be a subset while preserving existing matching behavior; treat the separately marked regex request as additional scope.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.