Package org.apache.coyote.http11
Class Http11OutputBuffer
java.lang.Object
org.apache.coyote.http11.Http11OutputBuffer
- All Implemented Interfaces:
HttpOutputBuffer,OutputBuffer
Provides buffering for the HTTP headers (allowing responses to be reset before they have been committed) and the link
to the Socket for writing the headers (once committed) and the response body. Note that buffering of the response
body happens at a higher level.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classThis class is an output buffer which will write data to a socket. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected OutputFilter[]Active filters for the current request.protected longBytes written to client for the current requestprotected OutputFilter[]Filter library for processing the response body.protected final ByteBufferThe buffer used for header composition.protected intIndex of the last active filter.protected HttpOutputBufferUnderlying output buffer.protected final ResponseAssociated Coyote response.protected booleanFinished flag.protected static final StringManagerThe string manager for this package.protected SocketWrapperBase<?>Wrapper for socket where data will be written to. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedHttp11OutputBuffer(Response response, int headerBufferSize) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddActiveFilter(OutputFilter filter) Add an output filter to the active filters for the current response.voidaddFilter(OutputFilter filter) Add an output filter to the filter library.protected voidcommit()Commit the response.intdoWrite(ByteBuffer chunk) Write the given data to the response.voidend()Finish writing the current response.voidEnd the header block.voidflush()Flushes any unwritten data to the client.protected booleanflushBuffer(boolean block) Writes any remaining buffered data.longBytes written to the underlying socket.Get filters.booleanvoidinit(SocketWrapperBase<?> socketWrapper) protected final booleanIs standard Servlet blocking IO being used for output?protected final booleanisReady()voidEnd processing of current HTTP request.voidrecycle()Recycle the output buffer.voidvoidsendAck()voidsendHeader(MessageBytes name, MessageBytes value) Send a header.voidDeprecated.Unused.voidsendStatus(int status) Send the response status line.voidwrite(byte[] b) This method will write the contents of the specified byte buffer to the output stream, without filtering.protected void
-
Field Details
-
sm
The string manager for this package. -
response
Associated Coyote response. -
responseFinished
protected boolean responseFinishedFinished flag. -
headerBuffer
The buffer used for header composition. -
filterLibrary
Filter library for processing the response body. -
activeFilters
Active filters for the current request. -
lastActiveFilter
protected int lastActiveFilterIndex of the last active filter. -
outputStreamOutputBuffer
Underlying output buffer. -
socketWrapper
Wrapper for socket where data will be written to. -
byteCount
protected long byteCountBytes written to client for the current request
-
-
Constructor Details
-
Http11OutputBuffer
-
-
Method Details
-
addFilter
Add an output filter to the filter library. Note that calling this method resets the currently active filters to none.- Parameters:
filter- The filter to add
-
getFilters
Get filters.- Returns:
- The current filter library containing all possible filters
-
addActiveFilter
Add an output filter to the active filters for the current response.The filter does not have to be present in
getFilters().A filter can only be added to a response once. If the filter has already been added to this response then this method will be a NO-OP.
- Parameters:
filter- The filter to add
-
doWrite
Description copied from interface:OutputBufferWrite the given data to the response. The caller owns the chunks.- Specified by:
doWritein interfaceOutputBuffer- Parameters:
chunk- data to write- Returns:
- The number of bytes written which may be less than available in the input chunk
- Throws:
IOException- an underlying I/O error occurred
-
getBytesWritten
public long getBytesWritten()Description copied from interface:OutputBufferBytes written to the underlying socket. This includes the effects of chunking, compression, etc.- Specified by:
getBytesWrittenin interfaceOutputBuffer- Returns:
- Bytes written for the current request
-
flush
Description copied from interface:HttpOutputBufferFlushes any unwritten data to the client.- Specified by:
flushin interfaceHttpOutputBuffer- Throws:
IOException- If an I/O error occurs while flushing
-
end
Description copied from interface:HttpOutputBufferFinish writing the current response. It is acceptable to write extra bytes usingOutputBuffer.doWrite(java.nio.ByteBuffer)during the execution of this method.- Specified by:
endin interfaceHttpOutputBuffer- Throws:
IOException- If an I/O error occurs while writing to the client
-
recycle
public void recycle()Recycle the output buffer. This should be called when closing the connection. -
nextRequest
public void nextRequest()End processing of current HTTP request. Note: All bytes of the current request should have been already consumed. This method only resets all the pointers so that we are ready to parse the next HTTP request. -
init
-
sendAck
- Throws:
IOException
-
commit
Commit the response.- Throws:
IOException- an underlying I/O error occurred
-
writeHeaders
- Throws:
IOException
-
sendStatus
Deprecated.Unused. Will be removed in Tomcat 11. UsesendStatus(int).Send the response status line. -
sendStatus
public void sendStatus(int status) Send the response status line.- Parameters:
status- The HTTP status code to include in the status line
-
sendHeader
Send a header.- Parameters:
name- Header namevalue- Header value
-
endHeaders
public void endHeaders()End the header block. -
write
public void write(byte[] b) This method will write the contents of the specified byte buffer to the output stream, without filtering. This method is meant to be used to write the response header.- Parameters:
b- data to be written
-
flushBuffer
Writes any remaining buffered data.- Parameters:
block- Should this method block until the buffer is empty- Returns:
trueif data remains in the buffer (which can only happen in non-blocking mode) elsefalse.- Throws:
IOException- Error writing data
-
isBlocking
protected final boolean isBlocking()Is standard Servlet blocking IO being used for output?- Returns:
trueif this is blocking IO
-
isReady
protected final boolean isReady() -
hasDataToWrite
public boolean hasDataToWrite() -
registerWriteInterest
public void registerWriteInterest()
-