Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Body not parsed correctly with Content-Type=application/json;charset=utf-8 #148

Open
inneon opened this issue Oct 16, 2023 · 0 comments
Open

Comments

@inneon
Copy link

inneon commented Oct 16, 2023

Great repo - thanks for all the hard work.

The body is not parsed correctly when I send the Content-Type of application/json;charset=utf-8.

Minimal example

post-device.json:

{
  "description": "Creates a new device",
  "request": {
    "method": "POST",
    "path": "/devices",
    "headers": {
      "Content-Type":["application/json;charset=utf-8"] // Note- this line can be omitted with the same result
    }
  },
  "response": {
    "statusCode": 201,
    "headers": {
      "Content-Type": ["application/json"]
    },
    "body": "{\"deviceId\": \"{{fake.UUID}}\", \"externalId\":\"{{request.body.externalId}}\" }"
  },
  "control": {
    "priority": 10
  }
}

Failing request from the console

{
    "scheme": "http",
    "host": "localhost",
    "port": "8083",
    "method": "POST",
    "path": "/devices",
    "queryStringParameters": {},
    "fragment": "",
    "headers": {
        "Accept": [
            "*/*"
        ],
        "Accept-Encoding": [
            "gzip, deflate, br"
        ],
        "Connection": [
            "keep-alive"
        ],
        "Content-Length": [
            "29"
        ],
        "Content-Type": [
            "application/json;charset=utf-8"
        ],
        "Postman-Token": [
            "769d6d8c-3060-40f7-baf0-8d4a859bcf69"
        ],
        "User-Agent": [
            "PostmanRuntime/7.33.0"
        ]
    },
    "cookies": {},
    "body": "{\"externalId\":\"BC572903D0B6\"}"
}

Failing response (notice how {{request.body.externalId}} is present in the response body).

{
    "statusCode": 201,
    "headers": {
        "Content-Type": [
            "application/json"
        ]
    },
    "cookies": null,
    "body": "{\"deviceId\": \"2e904f11-a17b-4366-8772-3db85e4bc2bd\", \"externalId\":\"{{request.body.externalId}}\" }"
}

Working request - note that content type has changed to be "application/json" (no charset).

{
    "scheme": "http",
    "host": "localhost",
    "port": "8083",
    "method": "POST",
    "path": "/devices",
    "queryStringParameters": {},
    "fragment": "",
    "headers": {
        "Accept": [
            "*/*"
        ],
        "Accept-Encoding": [
            "gzip, deflate, br"
        ],
        "Connection": [
            "keep-alive"
        ],
        "Content-Length": [
            "29"
        ],
        "Content-Type": [
            "application/json"
        ],
        "Postman-Token": [
            "af6fcf80-e439-427d-a3cd-005bff4e50d6"
        ],
        "User-Agent": [
            "PostmanRuntime/7.33.0"
        ]
    },
    "cookies": {},
    "body": "{\"externalId\":\"BC572903D0B6\"}"
}

Working response

{
    "statusCode": 201,
    "headers": {
        "Content-Type": [
            "application/json"
        ]
    },
    "cookies": null,
    "body": "{\"deviceId\": \"b3479472-bd23-42c1-ad15-312eb9634434\", \"externalId\":\"BC572903D0B6\" }"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant