org.webbitserver.netty
Class NettyHttpResponse

java.lang.Object
  extended by org.webbitserver.netty.NettyHttpResponse
All Implemented Interfaces:
HttpResponse

public class NettyHttpResponse
extends Object
implements HttpResponse


Constructor Summary
NettyHttpResponse(org.jboss.netty.channel.ChannelHandlerContext ctx, org.jboss.netty.handler.codec.http.HttpResponse response, boolean isKeepAlive, Thread.UncaughtExceptionHandler exceptionHandler)
           
 
Method Summary
 Charset charset()
          Current Charset used to encode to response as.
 NettyHttpResponse charset(Charset charset)
          For text based responses, sets the Charset to encode the response as.
 boolean containsHeader(String name)
          Test to see if this response has a header of the specified name
 NettyHttpResponse content(byte[] content)
          Write binary based content back to the client.
 NettyHttpResponse content(ByteBuffer buffer)
          Write binary based content back to the client.
 NettyHttpResponse content(String content)
          Write text based content back to the client.
 NettyHttpResponse cookie(HttpCookie httpCookie)
          Adds a cookie
 NettyHttpResponse end()
          Marks the response as ended.
 NettyHttpResponse error(Throwable error)
          Marks the response as erroneous.
 NettyHttpResponse header(String name, Date value)
          Adds a Date (RFC 1123 format) HTTP header.
 NettyHttpResponse header(String name, long value)
          Adds a numeric HTTP header.
 NettyHttpResponse header(String name, String value)
          Adds an HTTP header.
 int status()
          Retrieve HTTP status code that this response is going to return.
 NettyHttpResponse status(int status)
          Sets the HTTP status code.
 NettyHttpResponse write(String content)
          Writes immediately to the client without closing the connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NettyHttpResponse

public NettyHttpResponse(org.jboss.netty.channel.ChannelHandlerContext ctx,
                         org.jboss.netty.handler.codec.http.HttpResponse response,
                         boolean isKeepAlive,
                         Thread.UncaughtExceptionHandler exceptionHandler)
Method Detail

charset

public NettyHttpResponse charset(Charset charset)
Description copied from interface: HttpResponse
For text based responses, sets the Charset to encode the response as.

If not set, defaults to UTF8.

Specified by:
charset in interface HttpResponse

charset

public Charset charset()
Description copied from interface: HttpResponse
Current Charset used to encode to response as.

Specified by:
charset in interface HttpResponse
See Also:
HttpResponse.charset(Charset)

status

public NettyHttpResponse status(int status)
Description copied from interface: HttpResponse
Sets the HTTP status code.

Defaults to 200 (OK).

Specified by:
status in interface HttpResponse

status

public int status()
Description copied from interface: HttpResponse
Retrieve HTTP status code that this response is going to return.

Specified by:
status in interface HttpResponse
See Also:
HttpResponse.status(int)

header

public NettyHttpResponse header(String name,
                                String value)
Description copied from interface: HttpResponse
Adds an HTTP header. Multiple HTTP headers can be added with the same name.

Specified by:
header in interface HttpResponse

header

public NettyHttpResponse header(String name,
                                long value)
Description copied from interface: HttpResponse
Adds a numeric HTTP header. Multiple HTTP headers can be added with the same name.

Specified by:
header in interface HttpResponse

header

public NettyHttpResponse header(String name,
                                Date value)
Description copied from interface: HttpResponse
Adds a Date (RFC 1123 format) HTTP header. Multiple HTTP headers can be added with the same name.

Specified by:
header in interface HttpResponse

containsHeader

public boolean containsHeader(String name)
Description copied from interface: HttpResponse
Test to see if this response has a header of the specified name

Specified by:
containsHeader in interface HttpResponse

cookie

public NettyHttpResponse cookie(HttpCookie httpCookie)
Description copied from interface: HttpResponse
Adds a cookie

Specified by:
cookie in interface HttpResponse
Parameters:
httpCookie - the cookie

content

public NettyHttpResponse content(String content)
Description copied from interface: HttpResponse
Write text based content back to the client.

Specified by:
content in interface HttpResponse
See Also:
HttpResponse.charset(Charset), HttpResponse.content(byte[])

content

public NettyHttpResponse content(byte[] content)
Description copied from interface: HttpResponse
Write binary based content back to the client.

Specified by:
content in interface HttpResponse
See Also:
HttpResponse.content(String)

content

public NettyHttpResponse content(ByteBuffer buffer)
Description copied from interface: HttpResponse
Write binary based content back to the client.

Specified by:
content in interface HttpResponse
See Also:
HttpResponse.content(String)

write

public NettyHttpResponse write(String content)
Description copied from interface: HttpResponse
Writes immediately to the client without closing the connection. (The HttpResponse.content(String) method caches content until HttpResponse.end() is called()

TODO: Make content write immediately instead and remove this method?

Specified by:
write in interface HttpResponse
Parameters:
content - what to write

error

public NettyHttpResponse error(Throwable error)
Description copied from interface: HttpResponse
Marks the response as erroneous. The error shall be displayed to the user (500 SERVER ERROR) and the connection closed.

Every response should have either HttpResponse.end() or HttpResponse.error(Throwable) called. No more operations should be performed on a response after these.

Specified by:
error in interface HttpResponse

end

public NettyHttpResponse end()
Description copied from interface: HttpResponse
Marks the response as ended. At this point any remaining data shall be flushed and the connection closed.

Every response should have either HttpResponse.end() or HttpResponse.error(Throwable) called. No more operations should be performed on a response after these.

Specified by:
end in interface HttpResponse


Copyright © 2012. All Rights Reserved.