org.webbitserver
Interface HttpResponse

All Known Implementing Classes:
HttpResponseWrapper, NettyHttpResponse, StubHttpResponse

public interface HttpResponse

Writes a response back to the client.

IMPORTANT: The connection will remain open until end() or error(Throwable) is called. Don't forget these!

Author:
Joe Walnes

Method Summary
 Charset charset()
          Current Charset used to encode to response as.
 HttpResponse 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
 HttpResponse content(byte[] content)
          Write binary based content back to the client.
 HttpResponse content(ByteBuffer buffer)
          Write binary based content back to the client.
 HttpResponse content(String content)
          Write text based content back to the client.
 HttpResponse cookie(HttpCookie httpCookie)
          Adds a cookie
 HttpResponse end()
          Marks the response as ended.
 HttpResponse error(Throwable error)
          Marks the response as erroneous.
 HttpResponse header(String name, Date value)
          Adds a Date (RFC 1123 format) HTTP header.
 HttpResponse header(String name, long value)
          Adds a numeric HTTP header.
 HttpResponse header(String name, String value)
          Adds an HTTP header.
 int status()
          Retrieve HTTP status code that this response is going to return.
 HttpResponse status(int status)
          Sets the HTTP status code.
 HttpResponse write(String content)
          Writes immediately to the client without closing the connection.
 

Method Detail

charset

HttpResponse charset(Charset charset)
For text based responses, sets the Charset to encode the response as.

If not set, defaults to UTF8.


charset

Charset charset()
Current Charset used to encode to response as.

See Also:
charset(Charset)

status

HttpResponse status(int status)
Sets the HTTP status code.

Defaults to 200 (OK).


status

int status()
Retrieve HTTP status code that this response is going to return.

See Also:
status(int)

header

HttpResponse header(String name,
                    String value)
Adds an HTTP header. Multiple HTTP headers can be added with the same name.


header

HttpResponse header(String name,
                    long value)
Adds a numeric HTTP header. Multiple HTTP headers can be added with the same name.


header

HttpResponse header(String name,
                    Date value)
Adds a Date (RFC 1123 format) HTTP header. Multiple HTTP headers can be added with the same name.


containsHeader

boolean containsHeader(String name)
Test to see if this response has a header of the specified name


cookie

HttpResponse cookie(HttpCookie httpCookie)
Adds a cookie

Parameters:
httpCookie - the cookie

content

HttpResponse content(String content)
Write text based content back to the client.

See Also:
charset(Charset), content(byte[])

write

HttpResponse write(String content)
Writes immediately to the client without closing the connection. (The content(String) method caches content until end() is called()

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

Parameters:
content - what to write

content

HttpResponse content(byte[] content)
Write binary based content back to the client.

See Also:
content(String)

content

HttpResponse content(ByteBuffer buffer)
Write binary based content back to the client.

See Also:
content(String)

error

HttpResponse error(Throwable error)
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 end() or error(Throwable) called. No more operations should be performed on a response after these.


end

HttpResponse end()
Marks the response as ended. At this point any remaining data shall be flushed and the connection closed.

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



Copyright © 2012. All Rights Reserved.