Hi, Our application is a consumer of an API , and ...
# general
k
Hi, Our application is a consumer of an API , and this API has multiple consumers .. This API is already in production .. And we do http POSTS to the provider with request body and they respond to it . Now we are creating contracts and noticed the provider verification is failing with the following error .. 1.1) includes header 'Content-Type' with value '"application/json;charset=UTF-8"' Expected header 'Content-Type' to have value '"application/json;charset=UTF-8"' but was '' We are using pact-cpp plugin to create contract and this by default adds a response header['Content-Type'] of "application/json;charset=UTF-8"' .. Checked with the provider and they are not setting response header even though the response is json .. How do we address this issue ? I know the right way is by asking the provider to add a content-Type which I have requested .. Is there any other ways ? btw, I tried setting responseheader='Content-Type'] explicitly to "" and as expected the response body in the contract became a long string ..
m
interesting, I think that might be something the framework adds by default. I wonder what happens if you remove it from the contract file - does that work?
👍 1
That would help us determine how to improve it
j
caveat: I have not delved into the C++ Pact SDK, having said that... The content type is often set automatically, which in some cases such as this can result in this kind of unexpected behaviour. An alternative to altering the header from the contract file would be to ensure the contract is never generated with said header. If the C++ SDK uses the Rust core under the hood, it should be possible to remove
Content-Type
after it is set. Alternatively, it might be possible to set the
Content-Type
header to an empty string and see whether the SDK honours that.
k
@Matt (pactflow.io / pact-js / pact-go), Removing interactions['response']['headers'] gets the contract verification to pass .. Also tried with empty headers , that too is working ..
👍 1
We can include a workaround to go and remove the response['headers'] from the generated contract, but having an option to skip it would make it neat and easy ..
m
Great to know! I guess you could do a post process before uploading using something like
jq
to remove that, but understandably it would be nice if this worked OOTB
Could you please raise a feature request here: https://github.com/pact-foundation/pact-reference/issues?
👍 1