Overview | Package | Class | Deprecated | Index | Help
| Groovy Documentation
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.vertx.groovy.core.http
[Groovy] Class HttpServerResponse

    java.lang.Object
      org.vertx.groovy.core.http.HttpServerResponse

All Implemented Interfaces:
  WriteStream

    class HttpServerResponse

Represents a server-side HTTP response.

An instance of this class is created and associated to every instance of HttpServerRequest that is created.

It allows the developer to control the HTTP response that is sent back to the client for a partcularHTTP request. It contains methods that allow HTTP headers and trailers to be set, and for a body to be written out to the response.

It also allows files to be streamed by the kernel directly from disk to the outgoing HTTP connection, bypassing user space altogether (where supported by the underlying operating system). This is a very efficient way of serving files from the server since buffers do not have to be read one by one from the file and written to the outgoing socket.

It implements WriteStream so it can be used with Pump to pump data with flow control.

Instances of this class are not thread-safe

Authors:
  Peter Ledbrook
  Tim Fox

Constructor Summary
`protected HttpServerResponse(HttpServerResponse jResponse)`

Method Summary
`void` | `close()` Close the underlying TCP connection
`void` | `closeHandler(groovy.lang.Closure handler)` Set a close handler for the response.
`void` | `drainHandler(groovy.lang.Closure handler)` {@inheritDoc}
`void` | `end(java.lang.String chunk)` Same as end(Buffer) but writes a String with the default encoding
`void` | `end(java.lang.String chunk, java.lang.String enc)` Same as end(Buffer) but writes a String with the specified encoding
`void` | `end(Buffer chunk)` Same as end() but writes some data to the response body before ending.
`void` | `end()` Ends the response.
`void` | `exceptionHandler(groovy.lang.Closure handler)` {@inheritDoc}
`java.util.Map` | `getHeaders()` @return The headers of the response
`int` | `getStatusCode()` Returns: The HTTP status code of the response.
`java.lang.String` | `getStatusMessage()` Returns: The HTTP status message of the response.
`java.util.Map` | `getTrailers()` @return The trailers of the response
`boolean` | `isWriteQueueFull()` {@inheritDoc}
`HttpServerResponse` | `leftShift(Buffer buff)` Same as write(Buffer)
`HttpServerResponse` | `leftShift(java.lang.String str)` Same as write(String)
`HttpServerResponse` | `putHeader(java.lang.String name, java.lang.Object value)` Put an HTTP header - fluent API
`HttpServerResponse` | `sendFile(java.lang.String filename)` Tell the kernel to stream a file as specified by `filename` directly from disk to the outgoing connection, bypassing userspace altogether (where supported by the underlying operating system.
`HttpServerResponse` | `setChunked(boolean chunked)` If `chunked` is `true`, this response will use HTTP chunked encoding, and each call to write to the body will correspond to a new HTTP chunk sent on the wire.
`void` | `setStatusCode(int code)` Set the status code
`void` | `setStatusMessage(java.lang.String msg)` Set the status message
`void` | `setWriteQueueMaxSize(int size)` {@inheritDoc}
`HttpServerResponse` | `write(Buffer chunk)` Write a Buffer to the response body.
`HttpServerResponse` | `write(java.lang.String chunk, java.lang.String enc)` Write a java.lang.String to the response body, encoded using the encoding `enc`.
`HttpServerResponse` | `write(java.lang.String chunk)` Write a java.lang.String to the response body, encoded in UTF-8.
`HttpServerResponse` | `write(Buffer chunk, groovy.lang.Closure doneHandler)` Write a Buffer to the response body.
`HttpServerResponse` | `write(java.lang.String chunk, java.lang.String enc, groovy.lang.Closure doneHandler)` Write a java.lang.String to the response body, encoded with encoding `enc`.
`HttpServerResponse` | `write(java.lang.String chunk, groovy.lang.Closure doneHandler)` Write a java.lang.String to the response body, encoded in UTF-8.
`void` | `writeBuffer(Buffer chunk)` {@inheritDoc}

Methods inherited from class java.lang.Object
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()

Constructor Detail

### HttpServerResponse

    protected HttpServerResponse(HttpServerResponse jResponse)

Method Detail

### close

    void close()

  Close the underlying TCP connection

### closeHandler

    void closeHandler(groovy.lang.Closure handler)

  Set a close handler for the response. This will be called if the underlying connection closes before the response is complete.
  Parameters:
    handler

### drainHandler

    void drainHandler(groovy.lang.Closure handler)

  {@inheritDoc}

### end

    void end(java.lang.String chunk)

  Same as end(Buffer) but writes a String with the default encoding

### end

    void end(java.lang.String chunk, java.lang.String enc)

  Same as end(Buffer) but writes a String with the specified encoding

### end

    void end(Buffer chunk)

  Same as end() but writes some data to the response body before ending. If the response is not chunked and no other data has been written then the Content-Length header will be automatically set

### end

    void end()

  Ends the response. If no data has been written to the response body, the actual response won't get written until this method gets called.

  Once the response has ended, it cannot be used any more.

### exceptionHandler

    void exceptionHandler(groovy.lang.Closure handler)

  {@inheritDoc}

### getHeaders

    java.util.Map getHeaders()

  Returns:
    The headers of the response

### getStatusCode

    int getStatusCode()

  Returns:
    The HTTP status code of the response. The default is `200` representing `OK`.

### getStatusMessage

    java.lang.String getStatusMessage()

  Returns:
    The HTTP status message of the response. If this is not specified a default value will be used depending on what statusCode has been set to.

### getTrailers

    java.util.Map getTrailers()

  Returns:
    The trailers of the response

### isWriteQueueFull

    boolean isWriteQueueFull()

  {@inheritDoc}

### leftShift

    HttpServerResponse leftShift(Buffer buff)

  Same as write(Buffer)

### leftShift

    HttpServerResponse leftShift(java.lang.String str)

  Same as write(String)

### putHeader

    HttpServerResponse putHeader(java.lang.String name, java.lang.Object value)

  Put an HTTP header - fluent API
  Parameters:
    `name` - The header name
    `value` - The header value
  Returns:
    A reference to this, so multiple method calls can be chained.

### sendFile

    HttpServerResponse sendFile(java.lang.String filename)

  Tell the kernel to stream a file as specified by `filename` directly from disk to the outgoing connection, bypassing userspace altogether (where supported by the underlying operating system. This is a very efficient way to serve files.

### setChunked

    HttpServerResponse setChunked(boolean chunked)

  If `chunked` is `true`, this response will use HTTP chunked encoding, and each call to write to the body will correspond to a new HTTP chunk sent on the wire. If chunked encoding is used the HTTP header `Transfer-Encoding` with a value of `Chunked` will be automatically inserted in the response.

  If `chunked` is `false`, this response will not use HTTP chunked encoding, and therefore if any data is written the body of the response, the total size of that data must be set in the `Content-Length` header before any data is written to the response body.

  An HTTP chunked response is typically used when you do not know the total size of the request body up front.

  Returns:
    A reference to this, so multiple method calls can be chained.

### setStatusCode

    void setStatusCode(int code)

  Set the status code
  Parameters:
    `code` - The code

### setStatusMessage

    void setStatusMessage(java.lang.String msg)

  Set the status message
  Parameters:
    `msg` - The message

### setWriteQueueMaxSize

    void setWriteQueueMaxSize(int size)

  {@inheritDoc}

### write

    HttpServerResponse write(Buffer chunk)

  Write a Buffer to the response body.

  Returns:
    A reference to this, so multiple method calls can be chained.

### write

    HttpServerResponse write(java.lang.String chunk, java.lang.String enc)

  Write a java.lang.String to the response body, encoded using the encoding `enc`.

  Returns:
    A reference to this, so multiple method calls can be chained.

### write

    HttpServerResponse write(java.lang.String chunk)

  Write a java.lang.String to the response body, encoded in UTF-8.

  Returns:
    A reference to this, so multiple method calls can be chained.

### write

    HttpServerResponse write(Buffer chunk, groovy.lang.Closure doneHandler)

  Write a Buffer to the response body. The `doneHandler` is called after the buffer is actually written to the wire.

  Returns:
    A reference to this, so multiple method calls can be chained.

### write

    HttpServerResponse write(java.lang.String chunk, java.lang.String enc, groovy.lang.Closure doneHandler)

  Write a java.lang.String to the response body, encoded with encoding `enc`. The `doneHandler` is called after the buffer is actually written to the wire.

  Returns:
    A reference to this, so multiple method calls can be chained.

### write

    HttpServerResponse write(java.lang.String chunk, groovy.lang.Closure doneHandler)

  Write a java.lang.String to the response body, encoded in UTF-8. The `doneHandler` is called after the buffer is actually written to the wire.

  Returns:
    A reference to this, so multiple method calls can be chained.

### writeBuffer

    void writeBuffer(Buffer chunk)

  {@inheritDoc}

Groovy Documentation