Skip to content

consumes with mime type parameters blocks all content types #136

Open
@nlsun

Description

@nlsun

What I See

Setting a parameter in the mime type (e.g. charset=utf-8 in text/plain;charset=utf-8) inside the consumes field in the swagger file ends up not matching any request.

You get the error

{"code":415,"message":"unsupported media type \"text/plain\", only [text/plain; charset=utf-8] are allowed"}

even if the client content type is set to text/plain; charset=utf-8

Sample swagger consumes line:

definitions:
  '/test/{id}':
    post:
      consumes:
        - text/plain; charset=utf-8

What I think is happening

It looks like the problem is that we're doing a string match of the parsed request mime type (text/plain), against the "allowed" mime types (text/plain; charset=utf-8)

if swag.ContainsStringsCI(allowed, mt) {

I talked briefly with @casualjim on slack and his opinion on this is:

I’m leaning towards saying it should only match the base + any parameters the client sends

So it seems like the behavior should be changed to

  1. Pass, client sends text/plain and server accepts text/plain;charset=utf-8
  2. Fail, client sends text/plain;blah=true and server accepts text/plain;charset=utf-8
  3. Pass, client sends text/plain;charset=utf-8 and server accepts text/plain
  4. Pass, client sends text/plain;charset=utf-8 and server accepts text/plain;charset=utf-8
  5. Fail, client sends text/plain;charset=utf-8 and server accepts text/plain;charset=ascii

I'll try and submit a patch for this when I get a chance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions