Description
Response is interpreted as JSON even if response's Content-Type is "text/plain;charset=UTF-8".
In my case, I have an API returning a TOML document (starting with a '['). Instead of receiving a plain TOML document as a string, the response is interpreted as JSON.
Thank you!
Steps to Reproduce
Here is a feature that:
- sets up a mock-server returning a TOML document
- call the mock-server
- check that the document received is exactly the one sent
Feature: content-type
Background:
* def server = karate.start({ mock: 'classpath:mock-server.feature', port: 0 })
* def mockUrl = 'http://localhost:' + server.port
Scenario: content-type - handle response with Content-Type text/plain;charset=UTF-8
Given url mockUrl + '/config'
When method GET
Then status 200
* print 'content-type:', responseHeaders['Content-Type']
* print 'response:', response
* match response contains '[agent]\n interval = \"1s\"\n round_interval = true\n\n[[processors.date]]\n order=1'
mock-server.feature
Feature: Mock API returning text/plain;charset=UTF-8
Scenario: pathMatches('/config') && methodIs('get')
* def responseStatus = 200
* string response = "[agent]\n interval = \"1s\"\n round_interval = true\n\n[[processors.date]]\n order=1"
Expected Behavior
response variable should contain the body as a string, not as a list
Output of the scenario is:
10:44:17.962 [ForkJoinPool.commonPool-worker-1] INFO karate.scenario - content-type: ["text/plain; charset=UTF-8"]
10:44:17.962 [ForkJoinPool.commonPool-worker-1] INFO karate.scenario - response: ["agent"]
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.600 s <<< FAILURE! -- in it.eutelsat.karate.KarateTest
[ERROR] it.eutelsat.karate.KarateTest.[1:8] content-type - handle response with Content-Type text/plain;charset=UTF-8 -- Time elapsed: 0.012 s <<< ERROR!
io.karatelabs.core.KarateException:
match failed: CONTAINS
$ | actual does not contain expected | actual array does not contain expected item - [agent]
interval = "1s"
round_interval = true
[[processors.date]]
order=1 (LIST:STRING)
["agent"]
'[agent]
interval = "1s"
round_interval = true
[[processors.date]]
order=1'
$[0] | not equal (STRING:STRING)
'agent'
'[agent]
interval = "1s"
round_interval = true
[[processors.date]]
order=1'
Actual Behavior
response variable contains a list
Karate Version
2.1.1
Java Version
25
Operating System
Windows
Description
Response is interpreted as JSON even if response's Content-Type is "text/plain;charset=UTF-8".
In my case, I have an API returning a TOML document (starting with a '['). Instead of receiving a plain TOML document as a string, the response is interpreted as JSON.
Thank you!
Steps to Reproduce
Here is a feature that:
mock-server.feature
Expected Behavior
response variable should contain the body as a string, not as a list
Output of the scenario is:
Actual Behavior
response variable contains a list
Karate Version
2.1.1
Java Version
25
Operating System
Windows