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

Make status code configurable #723

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions java/org/apache/coyote/http11/Http11Processor.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ public class Http11Processor extends AbstractProcessor {
*/
private SendfileDataBase sendfileData = null;

/**
* Indicates if a bad request was received (if true, the connection will be closed at the end of the request)
*/
private boolean badRequest = false;


public Http11Processor(AbstractHttp11Protocol<?> protocol, Adapter adapter) {
super(adapter);
Expand Down Expand Up @@ -190,7 +195,7 @@ public Http11Processor(AbstractHttp11Protocol<?> protocol, Adapter adapter) {
* Determine if we must drop the connection because of the HTTP status code. Use the same list of codes as
* Apache/httpd.
*/
private static boolean statusDropsConnection(int status) {
protected boolean statusDropsConnection(int status) {
return status == 400 /* SC_BAD_REQUEST */ || status == 408 /* SC_REQUEST_TIMEOUT */ ||
status == 411 /* SC_LENGTH_REQUIRED */ || status == 413 /* SC_REQUEST_ENTITY_TOO_LARGE */ ||
status == 414 /* SC_REQUEST_URI_TOO_LONG */ || status == 500 /* SC_INTERNAL_SERVER_ERROR */ ||
Expand Down Expand Up @@ -251,6 +256,7 @@ public SocketState service(SocketWrapperBase<?> socketWrapper) throws IOExceptio
keepAlive = true;
openSocket = false;
readComplete = true;
badRequest = false;
boolean keptAlive = false;
SendfileState sendfileState = SendfileState.DONE;

Expand Down Expand Up @@ -851,6 +857,7 @@ private void prepareInputFilters(MimeHeaders headers) throws IOException {

private void badRequest(String errorKey) {
response.setStatus(400);
badRequest = true;
setErrorState(ErrorState.CLOSE_CLEAN, null);
if (log.isDebugEnabled()) {
log.debug(sm.getString(errorKey));
Expand Down Expand Up @@ -980,7 +987,7 @@ protected final void prepareResponse() throws IOException {

// If we know that the request is bad this early, add the
// Connection: close header.
if (keepAlive && statusDropsConnection(statusCode)) {
if (keepAlive && (badRequest || statusDropsConnection(statusCode))) {
keepAlive = false;
}
if (!keepAlive) {
Expand Down