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

Why does negotiation does not work for multiple types in the accept header? #100

Closed
frisi opened this issue Nov 21, 2019 · 2 comments
Closed

Comments

@frisi
Copy link

frisi commented Nov 21, 2019

Current state:

currently plone.rest returns a 404 for a request to the following service

  <plone:service
      method="GET"
      accept="application/json"
      for="Products.CMFPlone.interfaces.IPloneSiteRoot"
      factory=".rest.MyService"
      name="@servicename"
      permission="zope2.View"
      />

when the request is made with https://httpie.org/ like this

http --json GET https://server.com/@servicename
HTTP/1.1 404 Not Found
...

Reason:

https://github.com/plone/plone.rest/blob/1.6.0/src/plone/rest/negotiation.py#L27
also documented in the docstring:

Only Accept headers containing exactly one media type are considered for negotiation.

and httpie sends two media types in the accept header "Accept": "application/json, */*",

http --debug --json GET https://server.com/@servicename
HTTPie 0.9.8
...
>>> requests.request(**{
    "allow_redirects": false,
    "auth": "None",
    "cert": "None",
    "data": "",
    "files": {},
    "headers": {
        "Accept": "application/json, */*",
        "Content-Type": "application/json",
        "User-Agent": "HTTPie/0.9.8"
    },
    "method": "get",
    "params": {},
    "proxies": {},
    "stream": true,
    "timeout": 30,
    "url": "https://server.com/@servicename",
    "verify": true
})

Possible solution

use first media type mentioned in accept header (if multiple are given)

[or even return the service if one of the accept types matches.]

@frisi
Copy link
Author

frisi commented Nov 28, 2019

@buchi as you seem to have written the docstring (d587089): may i ask you to elaborate why this decision has been made?
thank you!

@tiberiuichim
Copy link
Contributor

tiberiuichim commented Dec 18, 2019

@frisi : see answer in #62 where I've asked the same question.

@jensens jensens closed this as completed Nov 25, 2020
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