Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2012-09-03 07:57:37 +0000
committerGreg Wilkins2012-09-03 07:57:37 +0000
commitfd01a1b4960aeaa0c45e82c28e2e8ea13c44cfd8 (patch)
tree99561b863ae3089ef7f58c8ded7dc68fe481d001
parenta922d44ce0ea6fd539fe41d090c1d20ddb58f8a8 (diff)
downloadorg.eclipse.jetty.project-fd01a1b4960aeaa0c45e82c28e2e8ea13c44cfd8.tar.gz
org.eclipse.jetty.project-fd01a1b4960aeaa0c45e82c28e2e8ea13c44cfd8.tar.xz
org.eclipse.jetty.project-fd01a1b4960aeaa0c45e82c28e2e8ea13c44cfd8.zip
JETTY-1541 fixed different behaviour for single byte writes
-rw-r--r--jetty-ajp/src/main/java/org/eclipse/jetty/ajp/Ajp13Generator.java49
-rw-r--r--jetty-http/src/main/java/org/eclipse/jetty/http/Generator.java10
-rw-r--r--jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java43
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/HttpOutput.java33
-rw-r--r--jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/http/ServerHTTPSPDYAsyncConnection.java9
5 files changed, 8 insertions, 136 deletions
diff --git a/jetty-ajp/src/main/java/org/eclipse/jetty/ajp/Ajp13Generator.java b/jetty-ajp/src/main/java/org/eclipse/jetty/ajp/Ajp13Generator.java
index 160e8b2b87..d43fecb6ab 100644
--- a/jetty-ajp/src/main/java/org/eclipse/jetty/ajp/Ajp13Generator.java
+++ b/jetty-ajp/src/main/java/org/eclipse/jetty/ajp/Ajp13Generator.java
@@ -245,7 +245,6 @@ public class Ajp13Generator extends AbstractGenerator
// Handle the _content
if (_head)
{
-
content.clear();
_content = null;
}
@@ -273,54 +272,6 @@ public class Ajp13Generator extends AbstractGenerator
/* ------------------------------------------------------------ */
/**
- * Add content.
- *
- * @param b
- * byte
- * @return true if the buffers are full
- * @throws IOException
- */
- public boolean addContent(byte b) throws IOException
- {
-
- if (_noContent)
- return false;
-
- if (_last || _state == STATE_END)
- throw new IllegalStateException("Closed");
-
- if (!_endp.isOpen())
- {
- _state = STATE_END;
- return false;
- }
-
- // Handle any unfinished business?
- if (_content != null && _content.length() > 0)
- {
- flushBuffer();
- if (_content != null && _content.length() > 0)
- throw new IllegalStateException("FULL");
- }
-
- _contentWritten++;
-
- // Handle the _content
- if (_head)
- return false;
-
- // we better check we have a buffer
- initContent();
-
- // Copy _content to buffer;
-
- _buffer.put(b);
-
- return _buffer.space() <= 1;
- }
-
- /* ------------------------------------------------------------ */
- /**
* Prepare buffer for unchecked writes. Prepare the generator buffer to receive unchecked writes
*
* @return the available space in the buffer.
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/Generator.java b/jetty-http/src/main/java/org/eclipse/jetty/http/Generator.java
index 78444e748b..1800cf9bf5 100644
--- a/jetty-http/src/main/java/org/eclipse/jetty/http/Generator.java
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/Generator.java
@@ -41,16 +41,6 @@ public interface Generator
*/
void addContent(Buffer content, boolean last) throws IOException;
- /* ------------------------------------------------------------ */
- /**
- * Add content.
- *
- * @param b byte
- * @return true if the buffers are full
- * @throws IOException
- */
- boolean addContent(byte b) throws IOException;
-
void complete() throws IOException;
void completeHeader(HttpFields responseFields, boolean last) throws IOException;
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 6d2c7dcc21..983a748b62 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
@@ -261,49 +261,6 @@ public class HttpGenerator extends AbstractGenerator
}
/* ------------------------------------------------------------ */
- /**
- * Add content.
- *
- * @param b byte
- * @return true if the buffers are full
- * @throws IOException
- */
- public boolean addContent(byte b) throws IOException
- {
- if (_noContent)
- throw new IllegalStateException("NO CONTENT");
-
- if (_last || _state==STATE_END)
- {
- LOG.warn("Ignoring extra content {}",Byte.valueOf(b));
- return false;
- }
-
- // Handle any unfinished business?
- if (_content != null && _content.length()>0 || _bufferChunked)
- {
- flushBuffer();
- if (_content != null && _content.length()>0 || _bufferChunked)
- throw new IllegalStateException("FULL");
- }
-
- _contentWritten++;
-
- // Handle the _content
- if (_head)
- return false;
-
- // we better check we have a buffer
- if (_buffer == null)
- _buffer = _buffers.getBuffer();
-
- // Copy _content to buffer;
- _buffer.put(b);
-
- return _buffer.space()<=(_contentLength == HttpTokens.CHUNKED_CONTENT?CHUNK_SPACE:0);
- }
-
- /* ------------------------------------------------------------ */
/** Prepare buffer for unchecked writes.
* Prepare the generator buffer to receive unchecked writes
* @return the available space in the buffer.
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpOutput.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpOutput.java
index b317a5e7c6..a9ef1f6714 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpOutput.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpOutput.java
@@ -44,6 +44,7 @@ public class HttpOutput extends ServletOutputStream
protected final AbstractHttpConnection _connection;
protected final AbstractGenerator _generator;
private boolean _closed;
+ private ByteArrayBuffer _onebyte;
// These are held here for reuse by Writer
String _characterEncoding;
@@ -116,6 +117,7 @@ public class HttpOutput extends ServletOutputStream
write(new ByteArrayBuffer(b));
}
+
/* ------------------------------------------------------------ */
/*
* @see java.io.OutputStream#write(int)
@@ -123,31 +125,12 @@ public class HttpOutput extends ServletOutputStream
@Override
public void write(int b) throws IOException
{
- if (_closed)
- throw new IOException("Closed");
- if (!_generator.isOpen())
- throw new EofException();
-
- // Block until we can add _content.
- while (_generator.isBufferFull())
- {
- _generator.blockForOutput(getMaxIdleTime());
- if (_closed)
- throw new IOException("Closed");
- if (!_generator.isOpen())
- throw new EofException();
- }
-
- // Add the _content
- if (_generator.addContent((byte)b))
- // Buffers are full so commit.
- _connection.commitResponse(Generator.MORE);
-
- if (_generator.isAllContentWritten())
- {
- flush();
- close();
- }
+ if (_onebyte==null)
+ _onebyte=new ByteArrayBuffer(1);
+ else
+ _onebyte.clear();
+ _onebyte.put((byte)b);
+ write(_onebyte);
}
/* ------------------------------------------------------------ */
diff --git a/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/http/ServerHTTPSPDYAsyncConnection.java b/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/http/ServerHTTPSPDYAsyncConnection.java
index 824cd0acce..01a82ca559 100644
--- a/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/http/ServerHTTPSPDYAsyncConnection.java
+++ b/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/http/ServerHTTPSPDYAsyncConnection.java
@@ -699,15 +699,6 @@ public class ServerHTTPSPDYAsyncConnection extends AbstractHttpConnection implem
}
@Override
- public boolean addContent(byte b) throws IOException
- {
- // In HttpGenerator, writing one byte only has a different path than
- // writing a buffer. Here we normalize these path to keep it simpler.
- addContent(new ByteArrayBuffer(new byte[]{b}), false);
- return false;
- }
-
- @Override
public void addContent(Buffer content, boolean last) throws IOException
{
// Keep the original behavior since adding content will

Back to the top