|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.faunos.util.net.http.ResponseHeaderStage
public class ResponseHeaderStage
Writes the HTTP response headers. This class is typically used in combination with a content Stagelet. This class is not itself stack-aware. That's because while the instance itself may be on the stack, it doesn't push any further stages on the stack: it's analogous to a function that calls no other function.
An instance must be configured before it becomes usable. At the very least, the status line must have been set (via one of the setStatusXxx() methods. The commit() method makes the configuration changes effective: it creates an array of ByteBuffers ready to be fed into the ScatteringByteChannel input parameter that will be passed in on the next invocation of write.
Field Summary | |
---|---|
static String |
DEFAULT_SERVER_NAME
|
static CannedResponses |
HEADERS
|
protected ByteBuffer[] |
responseHeaders
|
Constructor Summary | |
---|---|
ResponseHeaderStage()
|
Method Summary | |
---|---|
protected void |
addContent(List<ByteBuffer> response)
Hook exposed to subclasses for appending content to the end of the response header. |
void |
commit()
Commits the changes to the instance. |
void |
discard()
Discards the instance. |
IoState |
init(HandletContext context)
Commits the changes. |
protected Object |
lock()
Returns the object synchronized on when attempting to configure the instance. |
IoState |
read(ScatteringByteChannel in)
Not implemented. |
void |
setAllowGetHead()
Sets the "Allow" header to HEAD and GET (Allow: GET, HEAD). |
void |
setConnectionClose()
Sets the Connection: close response header. |
void |
setContentBase(String uri)
|
void |
setContentLength(long length)
Set the content-length HTTP header. |
void |
setContentLocation(String uri)
Sets the Content-Location header. |
void |
setContentType(ByteBuffer valueBuffer)
Expert. |
void |
setContentType(String contentType)
Sets the Content-Type HTTP header. |
void |
setContentTypeAppOctet()
|
void |
setContentTypeHtml()
Sets the content-type HTTP header to "text/html". |
void |
setContentTypePlainText()
Sets the content-type HTTP header to "text/plain". |
void |
setLocation(String uri)
|
void |
setProperty(String name,
String value)
|
void |
setServer(ByteBuffer name)
Expert. |
void |
setServer(String name)
Sets the server name. |
void |
setStatusBadRequest400()
Sets the status line to 400 (Bad Request). |
void |
setStatusMethodNotAllowed405()
Sets the status line to 405 (Method Not Allowed). |
void |
setStatusNotFound404()
Sets the status line to 404 (Not Found). |
void |
setStatusNotImplemented501()
Sets the status line to 501 (Not Implemented). |
void |
setStatusOkay200()
Sets the status line to 200 (OK). |
void |
setStatusRequestTooLong414()
Sets the status line to 414 (Request URI Too Long). |
void |
setStatusServerError500()
Sets the status line to 500 (Internal Server Error). |
IoState |
state()
Returns the state of the handlet. |
IoState |
unwind(IoState preState)
Not invoked in the base implementation, since this stage does not push another stagelet onto the stack. |
IoState |
write(GatheringByteChannel out)
Writes the HTTP headers. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final CannedResponses HEADERS
public static final String DEFAULT_SERVER_NAME
protected ByteBuffer[] responseHeaders
Constructor Detail |
---|
public ResponseHeaderStage()
Method Detail |
---|
public void commit() throws IllegalStateException
IllegalStateException
- If the status line has not been set.clear()
protected void addContent(List<ByteBuffer> response)
response
- the ByteBuffer contents can be added to this given listpublic void setConnectionClose()
public void setStatusOkay200()
public void setStatusBadRequest400()
public void setStatusNotFound404()
public void setStatusMethodNotAllowed405()
setAllowGetHead()
public void setStatusRequestTooLong414()
public void setStatusServerError500()
public void setStatusNotImplemented501()
public void setAllowGetHead()
public void setServer(String name)
public void setServer(ByteBuffer name)
public void setContentLocation(String uri)
public void setContentBase(String uri)
public void setLocation(String uri)
public void setContentType(String contentType)
contentType
- the string value of the content-type, sans the CRLFsetContentTypeHtml()
public void setContentType(ByteBuffer valueBuffer)
public void setContentTypeHtml()
public void setContentTypePlainText()
public void setContentTypeAppOctet()
public void setContentLength(long length)
length
- the content length in bytespublic void setProperty(String name, String value)
public IoState unwind(IoState preState)
unwind
in interface Stagelet
preState
- the state of the previous stage prior to its flipping to
DONE
public void discard()
Handlet
discard
in interface Handlet
public IoState init(HandletContext context)
Stagelet
contract, the instance is already on the stack.
This implementation does not use the passed in context argument.
init
in interface Handlet
context
- the context supplied by the instance's container (e.g.
serverpublic IoState read(ScatteringByteChannel in) throws IOException, UnsupportedOperationException
read
in interface Handlet
IOException
UnsupportedOperationException
public IoState state()
Handlet
state
in interface Handlet
public IoState write(GatheringByteChannel out) throws IOException
write
in interface Handlet
IOException
protected final Object lock()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |