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

Custom MIME type and versioning cause failures #1399

Closed
araines opened this issue Mar 21, 2016 · 5 comments
Closed

Custom MIME type and versioning cause failures #1399

araines opened this issue Mar 21, 2016 · 5 comments
Assignees

Comments

@araines
Copy link

araines commented Mar 21, 2016

FOSRestBundle 2.0 Beta 2
Symfony 2.7

I'm trying to implement a custom MIME type on my API, and require all clients to use it. This part appears to work fine until I start to try to add versioning.

config.yml

fos_rest:
    view:
        view_response_listener: force
        mime_types:
            json: ['application/vnd.foo.api+json;version=3']
    versioning:
        enabled: true
        resolvers:
            media_type:
                enabled: true
                regex: '/version=(?P<version>[0-9]+)/'
    format_listener:
        enabled: true
        rules:
            -
                path: '^/bracket/'
                priorities: ['json']
                fallback_format: ~
                prefer_extension: false

When I send a request, I get a HTTP406 (Not Acceptable) response:

curl -H 'Accept: application/vnd.foo.api+json;version=3' http://localhost:8080/bar/20

Individually, both of these features appear to work. For example, if I change my mime type as follows:

        mime_types:
            json: ['application/json;version=3']

And send a request:

curl -H 'Accept: application/json;version=3' http://localhost:8080/bar/20

Then I get the response I expect.

Also if I set it to my custom vendor descriptor:

        mime_types:
            json: ['application/vnd.foo.api+json;version=3']

curl -H 'Accept: application/vnd.foo.api+json' http://localhost:8080/bar/20

This also works (I get a HTTP200 response).

GuilhemN added a commit that referenced this issue Mar 21, 2016
GuilhemN added a commit that referenced this issue Mar 21, 2016
@GuilhemN GuilhemN mentioned this issue Mar 21, 2016
@GuilhemN
Copy link
Member

Hum there are apparently 2 bugs in cause.
The first one is in FOSRestBundle and is fixed by #1400 but the second one is caused by the symfony Request which removes all the parameters from the mime types (see here).

So until a fix is applied on symfony you have to use this in your config:

mime_types:
    json: ['application/vnd.foo.api+json;version=3', 'application/vnd.foo.api+json']

@GuilhemN
Copy link
Member

See symfony/symfony#18255

@araines
Copy link
Author

araines commented Mar 23, 2016

@Ener-Getick appreciate the speedy and detailed response :) Hopefully everything will get sorted at both ends soon!

@GuilhemN
Copy link
Member

@araines thank you for your report, we need people like you to tell us when a feature breaks and we don't catch it :-)
symfony/symfony#18255 doesn't contain major changes so I think it will be merged quickly.

fabpot added a commit to symfony/symfony that referenced this issue Mar 25, 2016
…ameters (Ener-Getick)

This PR was merged into the 2.3 branch.

Discussion
----------

[HttpFoundation] Fix support of custom mime types with parameters

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | FriendsOfSymfony/FOSRestBundle#1399
| License       | MIT

When using mime types with parameters, ``getFormat`` won't return the expected format as illustrated:
```php
$request = new Request();
$request->setFormat('custom', 'app/foo;param=bar');

$request->getFormat('app/foo;param=bar');
// will return null as the parameters are removed
```

So my proposal is to search the format corresponding to a mime type with its raw value or with the its parameters removed.

Commits
-------

f7ad285 [Request] Fix support of custom mime types with parameters
@GuilhemN
Copy link
Member

Fixed in symfony/symfony#18255, you'll be able to use this fix as soon as patch versions are released ;-)

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

3 participants