HttpResponse

public class HttpResponse extends DefaultFullHttpResponse

Constructors

HttpResponse

public HttpResponse(HttpRequest req, HttpVersion version, HttpResponseStatus status, ByteBuf buf)

Initialize a new response object

Parameters:
  • req – The HttpRequest object
  • version – The HTTP version
  • status – The status code and string for the response
  • buf – The response data

See also: HttpResponseStatus

HttpResponse

public HttpResponse(HttpRequest req, HttpVersion version, HttpResponseStatus status)

Initialize a new response object that has no data

Parameters:
  • req – The HttpRequest object
  • version – The HTTP version
  • status – The status code and string for the response

See also: HttpResponseStatus

Methods

forbidden

public static HttpResponse forbidden()

Returns a pre initialized response object with status code “403”

getHttpRequest

public HttpRequest getHttpRequest()

Get the request object for this response object.

Returns:HttpRequest object

See also: HttpRequest

internalServerError

public static HttpResponse internalServerError()

Returns a pre initialized response object with status code “500”

notFound

public static HttpResponse notFound()

Returns a pre initialized response object with status code “404”

setContent

public void setContent(byte[] data)

Set the data be sent in the response.

Parameters:
  • data – The actual data to be sent.

setContent

public void setContent(ByteBuf data)

setContentType

public void setContentType(String mimeType)

Set the content type of the response data

Parameters:
  • mimeType – The mime for the response content

setHttpRequest

public void setHttpRequest(HttpRequest req)

Sets the request object for which this response is being sent

statusCode

public int statusCode()

Get the status code set on this response object

Returns:integer status code

unAuthorized

public static HttpResponse unAuthorized()

Returns a pre initialized response object with status code “401”