juglr.net
Class HTTPResponseWriter
java.lang.Object
juglr.net.HTTPWriter
juglr.net.HTTPResponseWriter
public class HTTPResponseWriter
- extends HTTPWriter
A Writer
-like class for writing HTTP responses to a
SocketChannel
.This class does not automatically respect the
HTTP protocol and you must manually call the the write*
-methods
in the correct order to build a valid HTTP response. This is because
it must be possible to use this class in a fully optimized HTTP server.
Writing a correct HTTP response looks something like:
String msgString("Hello world of HTTP!");
resp.writeVersion(HTTP.Version.ONE_ZERO);
resp.writeStatus(HTTP.Status.OK);
resp.writeHeader("Content-Length", "" + msgString.length());
resp.writeHeader("Server", "juglr");
resp.startBody();
resp.writeBody(msgString);
resp.close();
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
HTTPResponseWriter
public HTTPResponseWriter(java.nio.channels.SocketChannel channel,
java.nio.ByteBuffer buf)
HTTPResponseWriter
public HTTPResponseWriter(java.nio.channels.SocketChannel channel)
reset
public HTTPResponseWriter reset(java.nio.channels.SocketChannel channel)
throws java.io.IOException
- Clear all state and reset the writer to start writing a new response
tp
channel
. If the previous channel is open it will be closed.
- Parameters:
channel
- the new socket channel to write to
- Returns:
- always returns
this
- Throws:
java.io.IOException
- if the previous channel was open and there was an
error when closing it
writeVersion
public void writeVersion(HTTP.Version version)
throws java.io.IOException
- Overrides:
writeVersion
in class HTTPWriter
- Throws:
java.io.IOException
writeStatus
public void writeStatus(HTTP.Status status)
throws java.io.IOException
- Throws:
java.io.IOException