I have a web application that can serve some requests to the same URL either as HTML or as JSON. So far I relied on the Accept HTTP header to determine what to return. Now there is a new requirement to be able to serve the JSON as a JSONP response if a specific URL parameter exists. Unfortunately most browsers request the src attribute of a <script> tag with an Accept header of */*.
At the moment i see two options around this and both have some drawbacks:
- When the
Acceptheader is*/*, check for acallbackparameter and if that parameter exists, serve JSONP. This might lead to the wrong content type when thecallbackparameter is used for different purposes. - Do not rely on the
Acceptheader any more and use different URL paths for different content types. This might break backwards compatibility of applications that consume the JSON or lead to duplicate URLs.
Is there any other way to detect JSONP requests?
Aucun commentaire:
Enregistrer un commentaire