Skip to content

Response contains twice the Allow header when using @RequestMapping(method=RequestMethod.OPTIONS) [SPR-7837] #12493

@spring-projects-issues

Description

@spring-projects-issues

Hans Desmet opened SPR-7837 and commented

Given following configuration of the DispatcherServlet in web.xml


<servlet>
<servlet-name>springDispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springControllers.xml</param-value>
</init-param>
<init-param>
<param-name>dispatchOptionsRequest</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springDispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

And the following MVC Controller:


@Controller
@RequestMapping("/persons")
public class PersonController {
@RequestMapping(method = RequestMethod.OPTIONS)
public ResponseEntity getPersonsOptions() {
HttpHeaders headers = new HttpHeaders();
headers.setAllow(EnumSet.of(HttpMethod.GET, HttpMethod.POST));
return new ResponseEntity(headers, HttpStatus.OK);
}
}

When you do a request to the URI /persons with the HTTP method OPTIONS, you get a request which contains the Alow header TWICE:


  • once with the value GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS
    this is incorrect and most likely generated by the standard HttpServlet behavior of OPTIONS requests
  • and once with te value GET,POST (this is correct)

Affects: 3.0.5

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