@@ -41,11 +41,9 @@ public class JerseyExpectContinueHandler extends ChannelInboundHandlerAdapter {
4141 HttpResponseStatus .METHOD_NOT_ALLOWED ,
4242 HttpResponseStatus .EXPECTATION_FAILED );
4343
44- private static final List <HttpResponseStatus > errorStatuses = new ArrayList <>(finalErrorStatuses );
4544 private static final List <HttpResponseStatus > statusesToBeConsidered = new ArrayList <>(reSendErrorStatuses );
4645
4746 static {
48- errorStatuses .addAll (reSendErrorStatuses );
4947 statusesToBeConsidered .addAll (finalErrorStatuses );
5048 statusesToBeConsidered .add (HttpResponseStatus .CONTINUE );
5149 }
@@ -59,15 +57,14 @@ public class JerseyExpectContinueHandler extends ChannelInboundHandlerAdapter {
5957 @ Override
6058 public void channelRead (ChannelHandlerContext ctx , Object msg ) throws Exception {
6159
62- if (checkExpectResponse (msg )) {
60+ if (checkExpectResponse (msg ) || checkInvalidExpect ( msg ) ) {
6361 currentState = ExpectationState .AWAITING ;
6462 }
6563 switch (currentState ) {
6664 case AWAITING :
6765 final HttpResponse response = (HttpResponse ) msg ;
6866 status = response .status ();
69-
70- boolean handshakeDone = processErrorStatuses (status , ctx ) || msg instanceof FullHttpMessage ;
67+ boolean handshakeDone = processErrorStatuses (status ) || msg instanceof FullHttpMessage ;
7168 currentState = (handshakeDone ) ? ExpectationState .IDLE : ExpectationState .FINISHING ;
7269 processLatch ();
7370 return ;
@@ -92,15 +89,22 @@ private boolean checkExpectResponse(Object msg) {
9289 return false ;
9390 }
9491
95- boolean processErrorStatuses (HttpResponseStatus status , ChannelHandlerContext ctx )
96- throws InterruptedException {
92+ private boolean checkInvalidExpect (Object msg ) {
93+ return (ExpectationState .IDLE .equals (currentState )
94+ && msg instanceof HttpResponse
95+ && (HttpResponseStatus .CONTINUE .equals (((HttpResponse ) msg ).status ())
96+ || reSendErrorStatuses .contains (((HttpResponse ) msg ).status ()))
97+ );
98+ }
99+
100+ boolean processErrorStatuses (HttpResponseStatus status ) {
97101 if (reSendErrorStatuses .contains (status )) {
98102 propagateLastMessage = true ;
99103 }
100104 return (finalErrorStatuses .contains (status ));
101105 }
102106
103- boolean processExpectationStatus ()
107+ void processExpectationStatus ()
104108 throws TimeoutException , IOException {
105109 if (status == null ) {
106110 throw new TimeoutException (); // continue without expectations
@@ -120,7 +124,6 @@ boolean processExpectationStatus()
120124 .EXPECT_100_CONTINUE_FAILED_REQUEST_SHOULD_BE_RESENT ()); // Re-send request without expectations
121125 }
122126
123- return true ;
124127 }
125128
126129 void resetHandler () {
0 commit comments