pact-foundation / pact-specification

Describes the pact format and verification specifications
MIT License
295 stars 28 forks source link

Content-Type resolution #60

Open 0xorial opened 6 years ago

0xorial commented 6 years ago

From specs

If the Content-Type header, is not present, then:

1. OPTIONAL - The content type can be determined from the first few characters of the body (know as a magic number test).
2. default to either application/json (as V1) or text/plain.

Shouldn't specification be specific about that? For example now I assumed "application/json" by default, so my implementation conforms to specs, but it fails some test-cases, because they assume "text/plain" by default.

bethesque commented 6 years ago

I think I made the Ruby impl assume text/plain by default, because then it would default to doing a plain text match on anything that didn't have a content type, and wouldn't blow up if it tried to parse something that it couln't. I'd prefer this to guessing, as it pushes the user in the direction of specifying a Content-Type. I wanted to make life hard for them if they didn't! @uglyog what does the java impl do? I have vague memories of it defaulting to application/json.

uglyog commented 6 years ago

JVM version first checks the Content-Type header, then checks the first few bytes of the body, and then defaults to text/plain. But that is for matching. The DSLs will add a Content-Type=application/json if no content type is provided.

ViktoriiaVlasiuk commented 1 year ago

If my service does not expect Content-Type header in the request, my test will always fail...is there any way not to add this header automatically?