Closed JP-Ellis closed 4 months ago
Fixed the issue with the failing tests. Reason being that the Content-Type
header was not being set if header
were None
. The new behaviour is:
headers
is None
, create a HashMap
and populate itheaders
is Some(hm)
, then insert the new Content-Type
header only if it does not exist already. This means that if someone has explicitly set the content type header, this function will not override it.Before merging, I just want to update the docstring to make sure it lines up with the behaviour.
Docstring has been updated. @rholshausen, I'll leave you do a last check before merging 👍
I believe this change has possibly caused a regression in the pact-php compat and test suite, see mentioned PR.
Changes also consumed in following PR's.
There are xml tests in pact-js but they are only consumable on release of pact-js-core (unless locally tested)
Hmm, I was worried this change may have unintended repercussions, though was relieved to see the test suite to pass... Evidently an edge case was not covered.
I'll have a look at the PR that uncovered this unintended change, though given neither Pact Go or Pact JS picked up this issue, I'm wondering whether Tien may have unintentionally baked in the broken behaviour into a test?
Once I've figured out exactly the extent of the change, I'll update the changelog to highlight this change in behaviour in case it impacts anyone else in the future.
EDIT: So I have had a quick look at the way the tests/examples are implemented, and it appears that the XML description is built from scratch, and then encoded into JSON before being passed through the FFI. The logic implemented should detect the JSON content and parse it as before though. But let me dig into that a bit more later.
Ahh so I don't believe pact-js-core or pact-go covered it.
I think the detect content type from string is saying its application/json and it isn't being transformed into xml
I think its this bit of code
And I believe that we need to check if its actually xml, when intermediate json is detected
The logic should be fine.
There's two content types set at the start of that function:
detected_type
which is taken from the body string, andcontent_type
which is taken from the function argument, with a series of fallbacks.The main matching is done on the content_type
:
Then if that is XML, it checks if the body is JSON, and fallbacks to raw body parsing:
I'm also confused as to why the XML test within the FFI test suite passed, by the PHP one did not, as the one in this repo also uses the JSON body:
I would need to enable trace-level logging and run the Pact PHP tests to properly understand that is going on.
The logic of processing the body within the
pactffi_with_body
was not consistent across the various interaction types. This refactors the logic out into a separateprocess_body
function.Note that as a result of this change, the behaviour of the FFI may change.