Skip to content

Send an Allow header with the 405 response from HttpServlet - #1103

Merged
markt-asf merged 1 commit into
apache:mainfrom
arturobernalg:bz-405-allow-header
Oct 23, 2026
Merged

markt-asf merged 1 commit into
apache:mainfrom
arturobernalg:bz-405-allow-header

Conversation

@arturobernalg

Copy link
Copy Markdown
Member

Section 15.5.6 of RFC 9110 requires an origin server to generate an Allow header field in a 405 response, listing the methods supported by the target resource. The 405 sent by HttpServlet for a method the servlet does not implement did not include one, unlike the 405 sent by DefaultServlet, the TRACE handling and JSP pages.

HttpServlet now sets Allow before sending the 405, using the same value as the default doOptions(), which includes TRACE when the connector allows it. The calculation is moved to a private method that both use. The HTTP/1.0 and HTTP/0.9 case, which answers 400, is unchanged.

TestHttpServlet has two new tests that send an unsupported method to a servlet that implements doGet() and to one that implements doGet() and doPost(). Without the change they fail because there is no Allow header. With it they pass and the header matches what OPTIONS returns for the same servlet. The related tests pass (TestDefaultServletOptions, TestWebdavServlet, TestConnector, TestJspServlet, TestStandardWrapper, TestHttpServletResponseSendError and the HTTP/2 TestHttpServlet) and Checkstyle reports nothing for the changed files.

CGIServlet also sends a 405 without Allow. I have not changed it here because it needs a CGI test set-up.

Section 15.5.6 of RFC 9110 requires an origin server to generate an
Allow header field in a 405 response that lists the methods supported by
the target resource. The 405 response sent for a method the servlet does
not implement did not include one. Use the value that the default
OPTIONS handling generates.
@markt-asf
markt-asf merged commit fa8aacc into apache:main Oct 23, 2026
10 checks passed
@markt-asf

Copy link
Copy Markdown
Contributor

There is some-follow up work required. Commit to follow shortly and then I'll back-port.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants