Hi :slightly_smiling_face: Is it possible to speci...
# pact-jvm
i
Hi 🙂 Is it possible to specify a header exists in an HTTP response (without value matching) using
PactBuilder
(V4)?
u
There is a V4 notEmpty matcher that will do that.
I don't think any of the current DSLs allow setting that matcher for a header, though.
Actually, the new request and response builders can set that.
i
Hi @uglyog thank you for your answer! I am looking at
HttpResponseBuilder.kt
version 4.4.5 and can not see an overload with matcher Am I missing something?
u
Ah! It's missing. I have added it, it should be available in the next release
🙏 1
i
Thank you very much!
u
4.4.6 released
🙏 1
i
Hi @uglyog 🙂 where can I find documentation about this feature? I am using 4.4.7 and can not define the existence of a header using
PactBuilder
message has been deleted
u
When you say "can not define the existence of a header", what do you mean? By adding a header to a Pact interaction means it has to exist otherwise the verification will fail.
i
Hi @uglyog thank you for your answer 🙂 I want to add a header but do not care about its content. For example, I expect
x-request-id
header to be present but I do not know or care about its value.
u
There is a notEmpty matcher, but I have never tested that with headers, and I don't think the DSL lets you supply any matcher for the headers. You could use a simple regex like
.+
i
I did not find a
header
method that accepts a matcher or regex string in the DSL, have I missed something?
u
Use
matchHeader
i
Hi @uglyog I am using version
4.4.7
and can not find that definition in
HttpRequestBuilder.kt
. I could also not find `matchHeader`definition in
4.4.8
here... Am I missing something?
u
Oh, sorry, that's right. With the new DSL you can use a matching function with the methods, so you should be able to use the notEmpty matcher
Copy code
builder
      .header("A", regexp("\\d+", "111"))
Or
Copy code
builder
      .header('A', notEmpty('111'))
Those functions are found in
<http://au.com|au.com>.dius.pact.consumer.dsl.Matchers
🙏 1