Skip to content

Commit 22bba80

Browse files
committed
Issue #12775 avoid unneccesary exception in getInputStream
1 parent 12d1611 commit 22bba80

File tree

2 files changed

+11
-4
lines changed
  • jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet
  • jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested

2 files changed

+11
-4
lines changed

jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletApiRequest.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import org.eclipse.jetty.http.HttpField;
6464
import org.eclipse.jetty.http.HttpFields;
6565
import org.eclipse.jetty.http.HttpHeader;
66+
import org.eclipse.jetty.http.HttpHeaderValue;
6667
import org.eclipse.jetty.http.HttpStatus;
6768
import org.eclipse.jetty.http.HttpURI;
6869
import org.eclipse.jetty.http.HttpVersion;
@@ -916,9 +917,12 @@ public ServletInputStream getInputStream() throws IOException
916917
{
917918
if (_inputState != ServletContextRequest.INPUT_NONE && _inputState != ServletContextRequest.INPUT_STREAM)
918919
throw new IllegalStateException("READER");
920+
921+
// Try to write a 100 continue if it is necessary
922+
if (_inputState == ServletContextRequest.INPUT_NONE && _servletContextRequest.getHeaders().contains(HttpHeader.EXPECT, HttpHeaderValue.CONTINUE.asString()))
923+
_servletChannel.getResponse().writeInterim(HttpStatus.CONTINUE_100, HttpFields.EMPTY);
924+
919925
_inputState = ServletContextRequest.INPUT_STREAM;
920-
// Try to write a 100 continue, ignoring failure result if it was not necessary.
921-
_servletChannel.getResponse().writeInterim(HttpStatus.CONTINUE_100, HttpFields.EMPTY);
922926
return getServletRequestInfo().getHttpInput();
923927
}
924928

jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/Request.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -912,9 +912,12 @@ public ServletInputStream getInputStream() throws IOException
912912
{
913913
if (_inputState != INPUT_NONE && _inputState != INPUT_STREAM)
914914
throw new IllegalStateException("READER");
915+
916+
// Try to write a 100 continue if it is necessary.
917+
if (_inputState == INPUT_NONE && _coreRequest.getHeaders().contains(HttpHeader.EXPECT, HttpHeaderValue.CONTINUE.asString()))
918+
_channel.getCoreResponse().writeInterim(HttpStatus.CONTINUE_100, HttpFields.EMPTY);
919+
915920
_inputState = INPUT_STREAM;
916-
// Try to write a 100 continue, ignoring failure result if it was not necessary.
917-
_channel.getCoreResponse().writeInterim(HttpStatus.CONTINUE_100, HttpFields.EMPTY);
918921
return _input;
919922
}
920923

0 commit comments

Comments
 (0)