Questions tagged [content-negotiation]

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.

184 questions
4
votes
1 answer

How can I serve HTML and JSON requests from the same route, using Symfony 2 and FOSRestBundle, using headers in addition to the _format?

I am attempting to serve content in both html and json formats (I also want to eventually allow for xml as well) using Symfony and the FOSRestBundle (ver. 1.3). I have been successful at serving different content for routes using the _format…
Sean Quinn
  • 2,131
  • 1
  • 18
  • 48
4
votes
2 answers

ContentNegotiation: How to serve other than the highest ranking type from accept header

I have this Spring Java Configuration with several custom HttpMessageConverters: public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { configurer.favorParameter(true). ignoreAcceptHeader(false). …
Andreas
  • 303
  • 1
  • 17
4
votes
1 answer

How to use the JasperReportsMultiFormatView with ContentNegotiatingViewResolver?

I have html, json, and xml working fine with Spring's ContentNegotiatingViewResolver (Spring 3.2) Trying to get csv output using a jasperreports. Spring can find and parse the .jrxml file ok. Getting the following error when I try to view a .csv…
Neil McGuigan
  • 46,580
  • 12
  • 123
  • 152
4
votes
2 answers

Prioritizing text/html over other content types when client sends Accept: */*

I am trying to write a controller with Spring MVC 3.2 that consumes/produces both JSON and HTML. I have two handler methods that produce different content types: @Controller public class FooController { @RequestMapping(value="/foo",…
Tim Yates
  • 5,151
  • 2
  • 29
  • 29
4
votes
4 answers

Spring 3.2 content negotiation class cast exception

We develop a standard Java web application using Spring MVC, and have recently tried to upgrade from 3.0.6 to 3.2.0. Nearly of all our servlet responses are JSP or Json views, but there are some that are pdf requests, with extension 'pdf'. In Spring…
otter606
  • 335
  • 1
  • 4
  • 21
4
votes
3 answers

How do I configure the status code returned by my ASP.NET Web API service when the request has an unsupported Content-Type?

If a request is made to my Web API service that has a Content-Type header containing a type not supported by that service, it returns a 500 Internal Server Error status code with a message similar to the following: {"Message":"An error has…
Redwood
  • 66,744
  • 41
  • 126
  • 187
4
votes
2 answers

Is Content Negotiation broken?

I recently got interested in web crawlers but one thing isn't a very clear one to me. Imagine a simple crawler that would get the page, extract links from it and queue them for later processing the same way. How crawlers handle the case when…
Kreeki
  • 3,662
  • 6
  • 27
  • 33
3
votes
2 answers

How to disable content negotiation for Spring Actuators?

I'd like to disable Content-Negotiation when actuator endpoints /info and /health are called here is my configs file @Configuration public class InterceptorAppConfig implements WebMvcConfigurer { @Override public void…
Alex
  • 483
  • 1
  • 12
  • 23
3
votes
0 answers

How to set default response format in spring-mvc using 'Content Negotiation Manager' when invalid format is given?

I wanted to get response from spring-mvc-controller either in json or xml format depending on the parameter - 'format' in the URL. I am able to achieve this using ContentNegotiation as shown in below code. The only problem is if I give an invalid…
3
votes
1 answer

Is it possible to merge two json responses using nginx?

I have an existing express endpoint that looks like this: app.get(`${route}/:id`, async (req, res) => { try { const id = req.params.id; const result = await dbFn(id); res.send(result); } catch (err) { …
dwjohnston
  • 11,163
  • 32
  • 99
  • 194
3
votes
1 answer

If a weighted HTTP header has duplicate values, with differing weights, how should this be handled?

Values of request headers, such as Accept-Language, Accept-Encoding, etc., have either implicitly or explicitly weighted values (en; q=0.8 for instance). In the unlikely event that the parsed value of the complete field value yields ambiguous…
Decent Dabbler
  • 22,532
  • 8
  • 74
  • 106
3
votes
2 answers

web api: add data to the HttpResponseMessage

I have an action in my web api that is returning a HttpResponseMessage: public async Task Create([FromBody] AType payload) { if (payload == null) { throw new ArgumentNullException(nameof(payload)); } …
Buda Gavril
  • 21,409
  • 40
  • 127
  • 196
3
votes
0 answers

How to make an API throw 406 or 415 codes during content negotiation

When building a RESTful API, it is desirable to issue return codes of 406 (not acceptable) and 415 (Unsupported media type) when doing content negotiation. What is not clear to me is exactly how to return these codes in a WebAPI2 app that is using…
3
votes
3 answers

Serving XHTML as application/xhtml+xml with Ruby on Rails

I'm trying to get my Rails app to serve XHTML content properly, with the correct content-type of application/xhtml+xml. Ideally with content negotiation so that IE users get a chance to use the site too. Given that all the HTML generated by Rails is…
derkyjadex
  • 843
  • 7
  • 14
3
votes
1 answer

How to make Zf2 Apigilty accept client request with no Accept set in header

Recently I have upgraded my rest server to Zf2 Apigility, which the content negotiation settings are as follows, 'zf-content-negotiation' => array( 'controllers' => array( 'CloudSchoolBusFileApi\\V1\\Rest\\FileReceiver\\Controller' =>…
1 2
3
12 13