Content negotiation is a mechanism defined in the HTTP specification that makes it possible to serve different versions of a document (or more generally, a resource representation) at the same URI, so that user agents can specify which version fit their capabilities the best.
Questions tagged [content-negotiation]
184 questions
7
votes
2 answers
AddType application/x-httpd-php .php is not rendering PHP
Adding this code:
AddType application/x-httpd-php .php after
# AddEncoding x-compress .Z
# AddEncoding x-gzip .gz .tgz
#
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media…

Lapys
- 936
- 2
- 11
- 27
7
votes
2 answers
What is the WebMvcConfigurationSupport replacement in Spring Boot?
In traditional Spring MVC, I can extend WebMvcConfigurationSupport and do the following:
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false).
…

Abhijit Sarkar
- 21,927
- 20
- 110
- 219
7
votes
1 answer
How to configure custom MediaType in Spring MVC?
Using Spring MVC, I have controllers already working for both JSON and XML media formats.
In the content negotiation configuration, I would like to rely on Accept header only, and introduce a custom name media type, for example: "myXml"
My…

István Békési
- 993
- 4
- 16
- 27
7
votes
2 answers
How to get a response from the Nancy Negotiator?
I have a NancyContext and I need to get a Response with a body based on the correct content negotiator for the request. I think I can use Nancy's Negotiator class to add a model, set the status, and other things. But then, I need to return a subtype…

Byron Sommardahl
- 12,743
- 15
- 74
- 131
6
votes
2 answers
HTTP content negotiation conflicts in JAX-RS/Jersey?
I am enjoying the auto HTTP content negotiation of JAX-RS (specifically Jersey), i.e. its ability to route my resources by "Accept" and/or "Content-Type" headers. But I'm finding that sometimes it doesn't give me enough control when there is a…

mckamey
- 17,359
- 16
- 83
- 116
6
votes
0 answers
Springboot content negotiation with param doesn't resolve when deployed as a WAR
I am trying to format my response content type on a @RestController between json and xml. It seems to work in the case of Accept header or path extension (.json,.xml). My application is packaged as a WAR and deployed to a tomcat instance. However I…

cyril.thomas
- 61
- 5
6
votes
2 answers
Is there a C# or .NET class to handle HTTP Content Negotiation?
Is there a C# or .NET class to handle HTTP Content Negotiation with a User Agent?
I would like to be able to supply a list of acceptable Content Types, and have those negotiated with the browser to find the best match.

Jamie
- 71
- 3
6
votes
3 answers
Content negotiation ignored when using browser Back button
Here's the situation:
I have a web application which response to a request for a list of resources, lets say:
/items
This is initially requested directly by the web browser by navigating to that path. The browser uses it's standard "Accept" header…

Mark Renouf
- 30,697
- 19
- 94
- 123
6
votes
1 answer
How to make Rails parse a posted string as json without sending the 'Content-type: application/json' header?
Rails changes behaviour at several levels when the header 'Content-type: application/json' is sent:
submitted post body is parsed as json instead of just a string parameter
wrap_parameters :format => [:json] in…

Pascal Van Hecke
- 4,516
- 3
- 19
- 18
6
votes
4 answers
RESTful Content Negotiation in Rails
I'm looking to implement content negotiation on some resources in a Rails app. I'm using Mootools and will likely be able to tweak the content type accepted by an XMLHTTPRequest to "application/json".
Is there any way to pick up on this information…

Alexander Trauzzi
- 7,277
- 13
- 68
- 112
5
votes
0 answers
Spring URI PathVariable with file extension not working
I'm having trouble working out why the file extension (.jpg) in the following request is being stripped before calling my controller method:
GET http://blah.com/assets/picture.jpg
I've set the content negotiation to not favour path…

Shane Rowatt
- 1,951
- 3
- 27
- 44
5
votes
1 answer
Content negotiation using mod_rewrite / RewriteCond rules
I have a use case is to host a set of files (same RDF content with different serialization formats such as RDF/XML, Turtle, and JSON-LD) in Github pages and use a w3id URL as a permanent identifier.
Further, I want to have content negotiation on…

Nandana
- 1,240
- 8
- 17
5
votes
2 answers
How to redirect users based on browser language
I want to redirect users based on browser language, I figured out how to do this here, it works fine, here is the code(PHP):
if(preg_match('/en-US/', $_SERVER['HTTP_USER_AGENT']))
header("location:index.php");
else
…

Zack
- 397
- 1
- 8
- 16
5
votes
2 answers
Spring MVC: Applying different JSON serializer for different annotated controller method
I'm creating a REST service using annotated controllers and the content negotiation (@ResponceBody). I have two different controller methods returning instance of {{Foo}} that serves different use cases and I want the JSON representation of the…

Alex Vayda
- 6,154
- 5
- 34
- 50
4
votes
1 answer
What are the Pros and Cons of using URI vs Accept Headers for REST content format negotiation?
Based on info in the following question REST Content-Type: Should it be based on extension or Accept header?, I'm aware either custom URIs or specifying Accept Headers are 'acceptable' (pun intended) methods for for a REST-ish web service to…

Ray
- 40,256
- 21
- 101
- 138