From 1a476620304b3737edd33fc955b46b3d7dcbba63 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 9 Jul 2009 23:27:40 +0000 Subject: [PATCH] 282807 Better handling of 100 continues if response committed git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@535 7e9141cc-0065-0410-87d8-b60c137991c4 --- VERSION.txt | 1 + .../org/eclipse/jetty/http/HttpGenerator.java | 44 ++++++++++++++++++- .../eclipse/jetty/server/HttpConnection.java | 17 +++---- .../org/eclipse/jetty/server/Response.java | 18 +------- 4 files changed, 55 insertions(+), 25 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 6159b28e604..3ca380cef09 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -6,6 +6,7 @@ jetty-7.0.0.RC0 8 June 2009 + 280843 Buffer pool uses isHeader + 271535 Adding integration tests, and enabling RFC2616 tests + 281287 Handle date headers before 1 Jan 1970 + + 282807 Better handling of 100 continues if response committed. jetty-7.0.0.M4 1 June 2009 + 281059 NPE in QTP with debug on diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java index de9d9d4982f..9c89018fd1e 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java @@ -14,6 +14,7 @@ package org.eclipse.jetty.http; import java.io.IOException; +import java.io.InterruptedIOException; import org.eclipse.jetty.io.Buffer; import org.eclipse.jetty.io.BufferUtil; @@ -305,6 +306,45 @@ public class HttpGenerator extends AbstractGenerator // Should we flush the buffers? return super.isBufferFull() || _bufferChunked || _bypass || (_contentLength == HttpTokens.CHUNKED_CONTENT && _buffer != null && _buffer.space() < CHUNK_SPACE); } + + /* ------------------------------------------------------------ */ + public void send1xx(int code) throws IOException + { + if (_state != STATE_HEADER) + return; + + if (code<100||code>199) + throw new IllegalArgumentException("!1xx"); + Status status=__status[code]; + if (status==null) + throw new IllegalArgumentException(code+"?"); + + // get a header buffer + if (_header == null) + _header = _buffers.getHeader(); + + _header.put(status._responseLine); + _header.put(HttpTokens.CRLF); + + try + { + // nasty semi busy flush! + while(_header.length()>0) + { + int len = _endp.flush(_header); + if (len<0) + throw new EofException(); + if (len==0) + Thread.sleep(100); + } + } + catch(InterruptedException e) + { + Log.debug(e); + throw new InterruptedIOException(e.toString()); + } + + } /* ------------------------------------------------------------ */ public void completeHeader(HttpFields fields, boolean allContentAdded) throws IOException @@ -682,7 +722,7 @@ public class HttpGenerator extends AbstractGenerator } } - if (!has_server && _status>100 && getSendServerVersion()) + if (!has_server && _status>199 && getSendServerVersion()) _header.put(SERVER); // end the header. @@ -691,6 +731,8 @@ public class HttpGenerator extends AbstractGenerator _state = STATE_CONTENT; } + + /* ------------------------------------------------------------ */ /** diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java index 68ce3aed0ed..78fff21a328 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java @@ -307,12 +307,13 @@ public class HttpConnection implements Connection // If the client is expecting 100 CONTINUE, then send it now. if (_expect100Continue) { + // is content missing? if (((HttpParser)_parser).getHeaderBuffer()==null || ((HttpParser)_parser).getHeaderBuffer().length()<2) { - _generator.setResponse(HttpStatus.CONTINUE_100, null); - _generator.completeHeader(null, true); - _generator.complete(); - _generator.reset(false); + if (_generator.isCommitted()) + throw new IllegalStateException("Committed before 100 Continues"); + + ((HttpGenerator)_generator).send1xx(HttpStatus.CONTINUE_100); } _expect100Continue=false; } @@ -800,11 +801,11 @@ public class HttpConnection implements Connection switch(HttpHeaderValues.CACHE.getOrdinal(value)) { case HttpHeaderValues.CONTINUE_ORDINAL: - _expect100Continue=true; + _expect100Continue=_generator instanceof HttpGenerator; break; case HttpHeaderValues.PROCESSING_ORDINAL: - _expect102Processing=true; + _expect102Processing=_generator instanceof HttpGenerator; break; default: @@ -819,10 +820,10 @@ public class HttpConnection implements Connection switch(cb.getOrdinal()) { case HttpHeaderValues.CONTINUE_ORDINAL: - _expect100Continue=true; + _expect100Continue=_generator instanceof HttpGenerator; break; case HttpHeaderValues.PROCESSING_ORDINAL: - _expect102Processing=true; + _expect102Processing=_generator instanceof HttpGenerator; break; default: _expect=true; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java index f20430a1879..798354630a9 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java @@ -379,22 +379,8 @@ public class Response implements HttpServletResponse */ public void sendProcessing() throws IOException { - if (_connection.isExpecting102Processing()) - { - Generator g = _connection.getGenerator(); - if (g instanceof HttpGenerator) - { - HttpGenerator generator = (HttpGenerator)g; - boolean was_persistent=generator.isPersistent(); - generator.setResponse(102,null); - generator.completeHeader(null,true); - generator.setPersistent(true); - generator.complete(); - generator.flushBuffer(); - generator.reset(false); - generator.setPersistent(was_persistent); - } - } + if (_connection.isExpecting102Processing() && !isCommitted()) + ((HttpGenerator)_connection.getGenerator()).send1xx(HttpStatus.PROCESSING_102); } /* ------------------------------------------------------------ */