pact-foundation / pact-stub-server

Standalone pact stub server
MIT License
75 stars 19 forks source link

request headers ignored #24

Closed markglibres closed 4 years ago

markglibres commented 5 years ago

hi, i have a single endpoint and created two interactions that varies on a header value, but somehow the matchingRules for the headers are ignored...

"request": { "method": "POST", "path": "/data", "headers": { "requestid": "1234" }, "matchingRules": { "headers": { "requestid": { "matchers": [ { "match": "regex", "regex": "^1234$" } ] } } } }

"request": { "method": "POST", "path": "/data", "headers": { "requestid": "1234" }, "matchingRules": { "headers": { "requestid": { "matchers": [ { "match": "regex", "regex": "^((?!1234).)*$" } ] } } } }

no matter what the values are on requestid, it always returned the first interaction and I am getting this warn message:

[WARN] Found more than one pact request for method POST and path '/data/', using the first one

any ideas how do I solve this issue?

uglyog commented 5 years ago

The matching rule keys need to be singular, so

{
  "request": {
    "method": "POST",
    "path": "/data",
    "headers": {
      "requestid": "1234"
    },
    "matchingRules": {
      "header": {
        "requestid": {
          "matchers": [
            {
              "match": "regex",
              "regex": "^1234$"
            }
          ]
        }
      }
    }
  }
}

I have updated the warning message to be more explicit about what it is doing, essentially get all the comparisons for all interactions against the request, and choose the first one with the least number of mismatches.