Skip to content

@RequestMapping(headers="foo!=bar") does not work for non media type headers [SPR-8862] #13504

@spring-projects-issues

Description

@spring-projects-issues

Edward Sargisson opened SPR-8862 and commented

I am attempting to seemlessly handle requests for KML files from Google Maps API and return a gzip version when requested. Google Maps puts 'accept-encoding = gzip' into the header.

I have the following code:

@RequestMapping(value = "/course/{courseIdParam}.kml", method=RequestMethod.GET, headers="Accept-Encoding!=gzip")
@ResponseBodypublic void getCourseAsKml(@PathVariable final String courseIdParam, final ModelMap modelMap, final OutputStream outputStream, final HttpServletResponse response, final HttpServletRequest request) throws JAXBException, IOException {
}

@RequestMapping(value = "/course/{courseIdParam}.kml", method=RequestMethod.GET, headers="Accept-Encoding=gzip")
@ResponseBodypublic void getCourseAsKmz(@PathVariable final String courseIdParam, final ModelMap modelMap, final OutputStream outputStream, final HttpServletResponse response, final HttpServletRequest request) throws JAXBException, IOException {
}

Expected behaviour:
getCourseAsKmz should be called.
getCourseAsKml should not be called

Actual behaviour:
getCourseAsKml is called

I believe the problem is in ServletAnnotationMappingUtils.checkHeaders

else if (!value.equals(request.getHeader(key))) {
return negated;
}

I think the ! needs to be removed from the condition


Affects: 3.1 RC1

Referenced from: commits 173f307, e695a21

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions