JETTY-1541 fixed different behaviour for single byte writes
This commit is contained in:
parent
a922d44ce0
commit
fd01a1b496
|
@ -245,7 +245,6 @@ public class Ajp13Generator extends AbstractGenerator
|
|||
// Handle the _content
|
||||
if (_head)
|
||||
{
|
||||
|
||||
content.clear();
|
||||
_content = null;
|
||||
}
|
||||
|
@ -271,54 +270,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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -260,49 +260,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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
|
@ -698,15 +698,6 @@ public class ServerHTTPSPDYAsyncConnection extends AbstractHttpConnection implem
|
|||
return null;
|
||||
}
|
||||
|
||||
@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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue