Skip to content

Commit

Permalink
Refactor the expectation flag to move it to the request (since it is …
Browse files Browse the repository at this point in the history
…a property of the request)

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1706172 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Sep 30, 2015
1 parent 953479e commit 33808df
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
16 changes: 16 additions & 0 deletions java/org/apache/coyote/Request.java
Expand Up @@ -121,6 +121,10 @@ public Request() {
private long contentLength = -1; private long contentLength = -1;
private MessageBytes contentTypeMB = null; private MessageBytes contentTypeMB = null;
private String charEncoding = null; private String charEncoding = null;
/**
* Is there an expectation ?
*/
private boolean expectation = false;


private final ServerCookies serverCookies = new ServerCookies(INITIAL_COOKIE_SIZE); private final ServerCookies serverCookies = new ServerCookies(INITIAL_COOKIE_SIZE);
private final Parameters parameters = new Parameters(); private final Parameters parameters = new Parameters();
Expand Down Expand Up @@ -344,6 +348,17 @@ public String getHeader(String name) {
return headers.getHeader(name); return headers.getHeader(name);
} }



public void setExpectation(boolean expectation) {
this.expectation = expectation;
}


public boolean hasExpectation() {
return expectation;
}


// -------------------- Associated response -------------------- // -------------------- Associated response --------------------


public Response getResponse() { public Response getResponse() {
Expand Down Expand Up @@ -524,6 +539,7 @@ public void recycle() {
contentLength = -1; contentLength = -1;
contentTypeMB = null; contentTypeMB = null;
charEncoding = null; charEncoding = null;
expectation = false;
headers.recycle(); headers.recycle();
serverNameMB.recycle(); serverNameMB.recycle();
serverPort=-1; serverPort=-1;
Expand Down
28 changes: 10 additions & 18 deletions java/org/apache/coyote/http11/Http11Processor.java
Expand Up @@ -151,12 +151,6 @@ public class Http11Processor extends AbstractProcessor {
protected boolean contentDelimitation = true; protected boolean contentDelimitation = true;




/**
* Is there an expectation ?
*/
protected boolean expectation = false;


/** /**
* Regular expression that defines the restricted user agents. * Regular expression that defines the restricted user agents.
*/ */
Expand Down Expand Up @@ -678,15 +672,13 @@ public final void action(ActionCode actionCode, Object param) {
// Acknowledge request // Acknowledge request
// Send a 100 status back if it makes sense (response not committed // Send a 100 status back if it makes sense (response not committed
// yet, and client specified an expectation for 100-continue) // yet, and client specified an expectation for 100-continue)
if ((response.isCommitted()) || !expectation) { if (!response.isCommitted() && request.hasExpectation()) {
return; inputBuffer.setSwallowInput(true);
} try {

outputBuffer.sendAck();
inputBuffer.setSwallowInput(true); } catch (IOException e) {
try { setErrorState(ErrorState.CLOSE_NOW, e);
outputBuffer.sendAck(); }
} catch (IOException e) {
setErrorState(ErrorState.CLOSE_NOW, e);
} }
break; break;
} }
Expand Down Expand Up @@ -1227,7 +1219,8 @@ private boolean handleIncompleteRequestLineRead() {




private void checkExpectationAndResponseStatus() { private void checkExpectationAndResponseStatus() {
if (expectation && (response.getStatus() < 200 || response.getStatus() > 299)) { if (request.hasExpectation() &&
(response.getStatus() < 200 || response.getStatus() > 299)) {
// Client sent Expect: 100-continue but received a // Client sent Expect: 100-continue but received a
// non-2xx final response. Disable keep-alive (if enabled) // non-2xx final response. Disable keep-alive (if enabled)
// to ensure that the connection is closed. Some clients may // to ensure that the connection is closed. Some clients may
Expand All @@ -1248,7 +1241,6 @@ private void prepareRequest() {
http11 = true; http11 = true;
http09 = false; http09 = false;
contentDelimitation = false; contentDelimitation = false;
expectation = false;
sendfileData = null; sendfileData = null;


if (endpoint.isSSLEnabled()) { if (endpoint.isSSLEnabled()) {
Expand Down Expand Up @@ -1307,7 +1299,7 @@ private void prepareRequest() {
if (expectMB != null) { if (expectMB != null) {
if (expectMB.indexOfIgnoreCase("100-continue", 0) != -1) { if (expectMB.indexOfIgnoreCase("100-continue", 0) != -1) {
inputBuffer.setSwallowInput(false); inputBuffer.setSwallowInput(false);
expectation = true; request.setExpectation(true);
} else { } else {
response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED); response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
setErrorState(ErrorState.CLOSE_CLEAN, null); setErrorState(ErrorState.CLOSE_CLEAN, null);
Expand Down

0 comments on commit 33808df

Please sign in to comment.