apiaryio / api-blueprint

API Blueprint
https://apiblueprint.org
MIT License
8.65k stars 2.14k forks source link

Multipart request bodies need to use \r\n instead of only \n #401

Open honzajavorek opened 7 years ago

honzajavorek commented 7 years ago

Multipart request example in API Blueprint results in body asset containing newlines formed by \n only. However, such asset isn't valid and usable as raw HTTP payload, all infrastructure counts with \r\n being in place.

Dredd currently fixes this, but I consider it as a workaround. I think the API Blueprint format should take care of this and to provide user with a correct, raw HTTP representation of a body. I guess if other API description formats support multipart, let's say in some declarative way, or if https://github.com/apiaryio/api-blueprint/issues/100 gets implemented in API Blueprint, the API Elements asset should contain the body with \r\n, not with \n.


Example API Blueprint:

FORMAT: 1A

# Testing 'multipart/form-data' Request API

# POST /data

+ Request (multipart/form-data;boundary=---BOUNDARY)

    + Body

            ---BOUNDARY
            Content-Disposition: form-data; name="text"
            Content-Type: text/plain

            test equals to 42
            ---BOUNDARY
            Content-Disposition: form-data; name="json"; filename="filename.json"
            Content-Type: application/json

            {"test": 42}
            ---BOUNDARY--

+ Response 200 (application/json; charset=utf-8)

    + Body

            {"test": "OK"}

Resulting asset:

---BOUNDARY\nContent-Disposition: form-data; name="text"\nContent-Type: text/plain\n\ntest equals to 42\n---BOUNDARY\nContent-Disposition: form-data; name="json"; filename="filename.json"\nContent-Type: application/json\n\n{"test": 42}\n---BOUNDARY--\n

Expected resulting asset:

---BOUNDARY\r\nContent-Disposition: form-data; name="text"\r\nContent-Type: text/plain\r\n\r\ntest equals to 42\r\n---BOUNDARY\r\nContent-Disposition: form-data; name="json"; filename="filename.json"\r\nContent-Type: application/json\r\n\r\n{"test": 42}\r\n---BOUNDARY--\r\n