Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jetty 12.0 beta 2 HttpServletResponse::getStatus returns 0 by default #9955

Closed
poutsma opened this issue Jun 23, 2023 · 3 comments
Closed

Jetty 12.0 beta 2 HttpServletResponse::getStatus returns 0 by default #9955

poutsma opened this issue Jun 23, 2023 · 3 comments
Labels
Bug For general bugs on Jetty side

Comments

@poutsma
Copy link

poutsma commented Jun 23, 2023

Jetty version(s)
Jetty 12.0 beta 2

Description

Running a Servlet in version 12 beta 2, HttpServletResponse::getStatus returns 0 if a status has not yet been set with setStatus.

According the Section 6.1.1 of RFC 2616:

The Status-Code element is a 3-digit integer result code

0 is not a 3-digit integer, and therefore should not be returned from getStatus.

Though I can't find a reference of a default status code in the Servlet spec, all other HttpServletResponse implementations—including previous versions of Jetty—have a default status code of 200.

How to reproduce?

This simple Servlet will print the default status code, and prints 0 in Jetty 12, beta 2.

public static class StatusCodeServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("text/plain");
		resp.getWriter().write(Integer.toString(resp.getStatus()));
	}
}
@poutsma poutsma added the Bug For general bugs on Jetty side label Jun 23, 2023
@gregw
Copy link
Contributor

gregw commented Jun 23, 2023

Note that if left at 0, then jetty will send a 200 as 0 simple means not set and the default if not set is 200.
However, we can change the servlet APIs to always return 200, as they did in previous releases

@gregw
Copy link
Contributor

gregw commented Jun 23, 2023

Note that 0 means not set and the default when not set is 200, so 200 will be sent.
However, I will update the servlet API classes to represent 0 as 200 as they don't care about not-set

gregw added a commit that referenced this issue Jun 23, 2023
Fix #9955 zero status is 200 in servlet API
gregw added a commit that referenced this issue Jun 23, 2023
Fix #9955 zero status is 200 in servlet API
@joakime
Copy link
Contributor

joakime commented Jun 26, 2023

Merged in PR #9956

@joakime joakime closed this as completed Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For general bugs on Jetty side
Projects
None yet
Development

No branches or pull requests

3 participants