io.vertx.rxjava.core.http

## Class HttpServerResponse

- java.lang.Object
- - io.vertx.rxjava.core.http.HttpServerResponse

- All Implemented Interfaces:
    StreamBase, WriteStream<Buffer>

      public class HttpServerResponse
      extends Object
      implements WriteStream<Buffer>

  Represents a server-side HTTP response.

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

  It allows the developer to control the HTTP response that is sent back to the client for a particular HTTP 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.

  NOTE: This class has been automatically generated from the `original` non RX-ified interface using Vert.x codegen.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `HttpServerResponse(HttpServerResponse delegate)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `HttpServerResponse` | `bodyEndHandler(Handler<Void> handler)` Provide a handler that will be called just before the last part of the body is written to the wire and the response is ended.
    `long` | `bytesWritten()`
    `void` | `close()` Close the underlying TCP connection corresponding to the request.
    `boolean` | `closed()`
    `HttpServerResponse` | `closeHandler(Handler<Void> handler)` Set a close handler for the response.
    `HttpServerResponse` | `drainHandler(Handler<Void> handler)` Set a drain handler on the stream.
    `void` | `end()` Ends the response.
    `void` | `end(Buffer chunk)` Same as `end(java.lang.String)` but writes some data to the response body before ending.
    `void` | `end(String chunk)` Same as `end(java.lang.String)` but writes a String in UTF-8 encoding before ending the response.
    `void` | `end(String chunk, String enc)` Same as `end(java.lang.String)` but writes a String with the specified encoding before ending the response.
    `boolean` | `ended()`
    `HttpServerResponse` | `exceptionHandler(Handler<Throwable> handler)` Set an exception handler on the write stream.
    `Object` | `getDelegate()`
    `int` | `getStatusCode()`
    `String` | `getStatusMessage()`
    `MultiMap` | `headers()`
    `HttpServerResponse` | `headersEndHandler(Handler<Void> handler)` Provide a handler that will be called just before the headers are written to the wire.
    `boolean` | `headWritten()`
    `boolean` | `isChunked()`
    `static HttpServerResponse` | `newInstance(HttpServerResponse arg)`
    `HttpServerResponse` | `push(HttpMethod method, String path, Handler<AsyncResult<HttpServerResponse>> handler)` Like `push(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.rxjava.core.http.HttpServerResponse>>)` with the host copied from the current request.
    `HttpServerResponse` | `push(HttpMethod method, String path, MultiMap headers, Handler<AsyncResult<HttpServerResponse>> handler)` Like `push(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.rxjava.core.http.HttpServerResponse>>)` with the host copied from the current request.
    `HttpServerResponse` | `push(HttpMethod method, String host, String path, Handler<AsyncResult<HttpServerResponse>> handler)` Like `push(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.rxjava.core.http.HttpServerResponse>>)` with no headers.
    `HttpServerResponse` | `push(HttpMethod method, String host, String path, MultiMap headers, Handler<AsyncResult<HttpServerResponse>> handler)` Push a response to the client. The `handler` will be notified with a success when the push can be sent and with a failure when the client has disabled push or reset the push before it has been sent. The `handler` may be queued if the client has reduced the maximum number of streams the server can push concurrently. Push can be sent only for peer initiated streams and if the response is not ended.
    `Observable<HttpServerResponse>` | `pushObservable(HttpMethod method, String path)` Like `push(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.rxjava.core.http.HttpServerResponse>>)` with the host copied from the current request.
    `Observable<HttpServerResponse>` | `pushObservable(HttpMethod method, String host, String path, MultiMap headers)` Push a response to the client. The `handler` will be notified with a success when the push can be sent and with a failure when the client has disabled push or reset the push before it has been sent. The `handler` may be queued if the client has reduced the maximum number of streams the server can push concurrently. Push can be sent only for peer initiated streams and if the response is not ended.
    `HttpServerResponse` | `putHeader(String name, String value)` Put an HTTP header
    `HttpServerResponse` | `putTrailer(String name, String value)` Put an HTTP trailer
    `void` | `reset()` Reset this HTTP/2 stream with the error code `0`.
    `void` | `reset(long code)` Reset this HTTP/2 stream with the error `code`.
    `HttpServerResponse` | `sendFile(String filename)` Same as `sendFile(java.lang.String)` using offset @code{0} which means starting from the beginning of the file.
    `HttpServerResponse` | `sendFile(String filename, Handler<AsyncResult<Void>> resultHandler)` Like `sendFile(java.lang.String)` but providing a handler which will be notified once the file has been completely written to the wire.
    `HttpServerResponse` | `sendFile(String filename, long offset)` Same as `sendFile(java.lang.String)` using length @code{Long.MAX_VALUE} which means until the end of the file.
    `HttpServerResponse` | `sendFile(String filename, long offset, Handler<AsyncResult<Void>> resultHandler)` Like `sendFile(java.lang.String)` but providing a handler which will be notified once the file has been completely written to the wire.
    `HttpServerResponse` | `sendFile(String filename, long offset, long length)` Ask the OS 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` | `sendFile(String filename, long offset, long length, Handler<AsyncResult<Void>> resultHandler)` Like `sendFile(java.lang.String)` but providing a handler which will be notified once the file has been completely written to the wire.
    `Observable<Void>` | `sendFileObservable(String filename)` Like `sendFile(java.lang.String)` but providing a handler which will be notified once the file has been completely written to the wire.
    `Observable<Void>` | `sendFileObservable(String filename, long offset)` Like `sendFile(java.lang.String)` but providing a handler which will be notified once the file has been completely written to the wire.
    `Observable<Void>` | `sendFileObservable(String filename, long offset, long length)` Like `sendFile(java.lang.String)` but providing a handler which will be notified once the file has been completely written to the wire.
    `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.
    `HttpServerResponse` | `setStatusCode(int statusCode)` Set the status code.
    `HttpServerResponse` | `setStatusMessage(String statusMessage)` Set the status message
    `HttpServerResponse` | `setWriteQueueMaxSize(int maxSize)` Set the maximum size of the write queue to `maxSize`.
    `int` | `streamId()`
    `MultiMap` | `trailers()`
    `HttpServerResponse` | `write(Buffer data)` Write some data to the stream.
    `HttpServerResponse` | `write(String chunk)` Write a `String` to the response body, encoded in UTF-8.
    `HttpServerResponse` | `write(String chunk, String enc)` Write a `String` to the response body, encoded using the encoding `enc`.
    `HttpServerResponse` | `writeContinue()` Used to write an interim 100 Continue response to signify that the client should send the rest of the request.
    `HttpServerResponse` | `writeCustomFrame(HttpFrame frame)` Like `writeCustomFrame(int, int, io.vertx.rxjava.core.buffer.Buffer)` but with an `HttpFrame`.
    `HttpServerResponse` | `writeCustomFrame(int type, int flags, Buffer payload)` Write an HTTP/2 frame to the response, allowing to extend the HTTP/2 protocol.
    `boolean` | `writeQueueFull()` This will return `true` if there are more bytes in the write queue than the value set using `setWriteQueueMaxSize(int)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface io.vertx.rxjava.core.streams.WriteStream

      `newInstance`

    - ### Methods inherited from interface io.vertx.rxjava.core.streams.StreamBase

      `newInstance`

- - ### Constructor Detail

    - #### HttpServerResponse

          public HttpServerResponse(HttpServerResponse delegate)

  - ### Method Detail

    - #### getDelegate

          public Object getDelegate()

      Specified by:
        `getDelegate` in interface `StreamBase`
      Specified by:
        `getDelegate` in interface `WriteStream<Buffer>`

    - #### writeQueueFull

          public boolean writeQueueFull()

      This will return `true` if there are more bytes in the write queue than the value set using `setWriteQueueMaxSize(int)`
      Specified by:
        `writeQueueFull` in interface `WriteStream<Buffer>`
      Returns:
        true if write queue is full

    - #### exceptionHandler

          public HttpServerResponse exceptionHandler(Handler<Throwable> handler)

      Description copied from interface: `WriteStream`
      Set an exception handler on the write stream.
      Specified by:
        `exceptionHandler` in interface `StreamBase`
      Specified by:
        `exceptionHandler` in interface `WriteStream<Buffer>`
      Parameters:
        `handler` - the exception handler
      Returns:
        a reference to this, so the API can be used fluently

    - #### write

          public HttpServerResponse write(Buffer data)

      Description copied from interface: `WriteStream`
      Write some data to the stream. The data is put on an internal write queue, and the write actually happens asynchronously. To avoid running out of memory by putting too much on the write queue, check the `WriteStream.writeQueueFull()` method before writing. This is done automatically if using a `Pump`.
      Specified by:
        `write` in interface `WriteStream<Buffer>`
      Parameters:
        `data` - the data to write
      Returns:
        a reference to this, so the API can be used fluently

    - #### setWriteQueueMaxSize

          public HttpServerResponse setWriteQueueMaxSize(int maxSize)

      Description copied from interface: `WriteStream`
      Set the maximum size of the write queue to `maxSize`. You will still be able to write to the stream even if there is more than `maxSize` bytes in the write queue. This is used as an indicator by classes such as `Pump` to provide flow control.
      Specified by:
        `setWriteQueueMaxSize` in interface `WriteStream<Buffer>`
      Parameters:
        `maxSize` - the max size of the write stream
      Returns:
        a reference to this, so the API can be used fluently

    - #### drainHandler

          public HttpServerResponse drainHandler(Handler<Void> handler)

      Description copied from interface: `WriteStream`
      Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write queue has been reduced to maxSize / 2. See `Pump` for an example of this being used.
      Specified by:
        `drainHandler` in interface `WriteStream<Buffer>`
      Parameters:
        `handler` - the handler
      Returns:
        a reference to this, so the API can be used fluently

    - #### getStatusCode

          public int getStatusCode()

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

    - #### setStatusCode

          public HttpServerResponse setStatusCode(int statusCode)

      Set the status code. If the status message hasn't been explicitly set, a default status message corresponding to the code will be looked-up and used.
      Parameters:
        `statusCode` -
      Returns:
        a reference to this, so the API can be used fluently

    - #### getStatusMessage

          public String getStatusMessage()

      Returns:
        the HTTP status message of the response. If this is not specified a default value will be used depending on what `setStatusCode(int)` has been set to.

    - #### setStatusMessage

          public HttpServerResponse setStatusMessage(String statusMessage)

      Set the status message
      Parameters:
        `statusMessage` -
      Returns:
        a reference to this, so the API can be used fluently

    - #### setChunked

          public 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 the total size of any data that is written in the respone body must be set in the `Content-Length` header before any data is written out.

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

      Parameters:
        `chunked` -
      Returns:
        a reference to this, so the API can be used fluently

    - #### isChunked

          public boolean isChunked()

      Returns:
        is the response chunked?

    - #### headers

          public MultiMap headers()

      Returns:
        The HTTP headers

    - #### putHeader

          public HttpServerResponse putHeader(String name,
                                              String value)

      Put an HTTP header
      Parameters:
        `name` - the header name
        `value` - the header value.
      Returns:
        a reference to this, so the API can be used fluently

    - #### trailers

          public MultiMap trailers()

      Returns:
        The HTTP trailers

    - #### putTrailer

          public HttpServerResponse putTrailer(String name,
                                               String value)

      Put an HTTP trailer
      Parameters:
        `name` - the trailer name
        `value` - the trailer value
      Returns:
        a reference to this, so the API can be used fluently

    - #### closeHandler

          public HttpServerResponse closeHandler(Handler<Void> handler)

      Set a close handler for the response. This will be called if the underlying connection closes before the response is complete.
      Parameters:
        `handler` - the handler
      Returns:
        a reference to this, so the API can be used fluently

    - #### write

          public HttpServerResponse write(String chunk,
                                          String enc)

      Write a `String` to the response body, encoded using the encoding `enc`.
      Parameters:
        `chunk` - the string to write
        `enc` - the encoding to use
      Returns:
        a reference to this, so the API can be used fluently

    - #### write

          public HttpServerResponse write(String chunk)

      Write a `String` to the response body, encoded in UTF-8.
      Parameters:
        `chunk` - the string to write
      Returns:
        a reference to this, so the API can be used fluently

    - #### writeContinue

          public HttpServerResponse writeContinue()

      Used to write an interim 100 Continue response to signify that the client should send the rest of the request. Must only be used if the request contains an "Expect:100-Continue" header
      Returns:
        a reference to this, so the API can be used fluently

    - #### end

          public void end(String chunk)

      Same as `end(java.lang.String)` but writes a String in UTF-8 encoding before ending the response.
      Parameters:
        `chunk` - the string to write before ending the response

    - #### end

          public void end(String chunk,
                          String enc)

      Same as `end(java.lang.String)` but writes a String with the specified encoding before ending the response.
      Parameters:
        `chunk` - the string to write before ending the response
        `enc` - the encoding to use

    - #### end

          public void end(Buffer chunk)

      Same as `end(java.lang.String)` 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 @code{Content-Length} header will be automatically set.
      Specified by:
        `end` in interface `WriteStream<Buffer>`
      Parameters:
        `chunk` - the buffer to write before ending the response

    - #### end

          public 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.

      Specified by:
        `end` in interface `WriteStream<Buffer>`

    - #### sendFile

          public HttpServerResponse sendFile(String filename)

      Same as `sendFile(java.lang.String)` using offset @code{0} which means starting from the beginning of the file.
      Parameters:
        `filename` - path to the file to serve
      Returns:
        a reference to this, so the API can be used fluently

    - #### sendFile

          public HttpServerResponse sendFile(String filename,
                                             long offset)

      Same as `sendFile(java.lang.String)` using length @code{Long.MAX_VALUE} which means until the end of the file.
      Parameters:
        `filename` - path to the file to serve
        `offset` - offset to start serving from
      Returns:
        a reference to this, so the API can be used fluently

    - #### sendFile

          public HttpServerResponse sendFile(String filename,
                                             long offset,
                                             long length)

      Ask the OS 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.

      The actual serve is asynchronous and may not complete until some time after this method has returned.

      Parameters:
        `filename` - path to the file to serve
        `offset` - offset to start serving from
        `length` - length to serve to
      Returns:
        a reference to this, so the API can be used fluently

    - #### sendFile

          public HttpServerResponse sendFile(String filename,
                                             Handler<AsyncResult<Void>> resultHandler)

      Like `sendFile(java.lang.String)` but providing a handler which will be notified once the file has been completely written to the wire.
      Parameters:
        `filename` - path to the file to serve
        `resultHandler` - handler that will be called on completion
      Returns:
        a reference to this, so the API can be used fluently

    - #### sendFileObservable

          public Observable<Void> sendFileObservable(String filename)

      Like `sendFile(java.lang.String)` but providing a handler which will be notified once the file has been completely written to the wire.
      Parameters:
        `filename` - path to the file to serve
      Returns:

    - #### sendFile

          public HttpServerResponse sendFile(String filename,
                                             long offset,
                                             Handler<AsyncResult<Void>> resultHandler)

      Like `sendFile(java.lang.String)` but providing a handler which will be notified once the file has been completely written to the wire.
      Parameters:
        `filename` - path to the file to serve
        `offset` - the offset to serve from
        `resultHandler` - handler that will be called on completion
      Returns:
        a reference to this, so the API can be used fluently

    - #### sendFileObservable

          public Observable<Void> sendFileObservable(String filename,
                                                     long offset)

      Like `sendFile(java.lang.String)` but providing a handler which will be notified once the file has been completely written to the wire.
      Parameters:
        `filename` - path to the file to serve
        `offset` - the offset to serve from
      Returns:

    - #### sendFile

          public HttpServerResponse sendFile(String filename,
                                             long offset,
                                             long length,
                                             Handler<AsyncResult<Void>> resultHandler)

      Like `sendFile(java.lang.String)` but providing a handler which will be notified once the file has been completely written to the wire.
      Parameters:
        `filename` - path to the file to serve
        `offset` - the offset to serve from
        `length` - the length to serve to
        `resultHandler` - handler that will be called on completion
      Returns:
        a reference to this, so the API can be used fluently

    - #### sendFileObservable

          public Observable<Void> sendFileObservable(String filename,
                                                     long offset,
                                                     long length)

      Like `sendFile(java.lang.String)` but providing a handler which will be notified once the file has been completely written to the wire.
      Parameters:
        `filename` - path to the file to serve
        `offset` - the offset to serve from
        `length` - the length to serve to
      Returns:

    - #### close

          public void close()

      Close the underlying TCP connection corresponding to the request.

    - #### ended

          public boolean ended()

      Returns:
        has the response already ended?

    - #### closed

          public boolean closed()

      Returns:
        has the underlying TCP connection corresponding to the request already been closed?

    - #### headWritten

          public boolean headWritten()

      Returns:
        have the headers for the response already been written?

    - #### headersEndHandler

          public HttpServerResponse headersEndHandler(Handler<Void> handler)

      Provide a handler that will be called just before the headers are written to the wire.

      This provides a hook allowing you to add any more headers or do any more operations before this occurs.

      Parameters:
        `handler` - the handler
      Returns:
        a reference to this, so the API can be used fluently

    - #### bodyEndHandler

          public HttpServerResponse bodyEndHandler(Handler<Void> handler)

      Provide a handler that will be called just before the last part of the body is written to the wire and the response is ended.

      This provides a hook allowing you to do any more operations before this occurs.

      Parameters:
        `handler` - the handler
      Returns:
        a reference to this, so the API can be used fluently

    - #### bytesWritten

          public long bytesWritten()

      Returns:
        the total number of bytes written for the body of the response.

    - #### streamId

          public int streamId()

      Returns:
        the id of the stream of this response, for HTTP/1.x

    - #### push

          public HttpServerResponse push(HttpMethod method,
                                         String host,
                                         String path,
                                         Handler<AsyncResult<HttpServerResponse>> handler)

      Like `push(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.rxjava.core.http.HttpServerResponse>>)` with no headers.
      Parameters:
        `method` -
        `host` -
        `path` -
        `handler` -
      Returns:

    - #### push

          public HttpServerResponse push(HttpMethod method,
                                         String path,
                                         MultiMap headers,
                                         Handler<AsyncResult<HttpServerResponse>> handler)

      Like `push(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.rxjava.core.http.HttpServerResponse>>)` with the host copied from the current request.
      Parameters:
        `method` -
        `path` -
        `headers` -
        `handler` -
      Returns:

    - #### push

          public HttpServerResponse push(HttpMethod method,
                                         String path,
                                         Handler<AsyncResult<HttpServerResponse>> handler)

      Like `push(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.rxjava.core.http.HttpServerResponse>>)` with the host copied from the current request.
      Parameters:
        `method` -
        `path` -
        `handler` -
      Returns:

    - #### pushObservable

          public Observable<HttpServerResponse> pushObservable(HttpMethod method,
                                                               String path)

      Like `push(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.rxjava.core.http.HttpServerResponse>>)` with the host copied from the current request.
      Parameters:
        `method` -
        `path` -
      Returns:

    - #### push

          public HttpServerResponse push(HttpMethod method,
                                         String host,
                                         String path,
                                         MultiMap headers,
                                         Handler<AsyncResult<HttpServerResponse>> handler)

      Push a response to the client.

      The `handler` will be notified with a success when the push can be sent and with a failure when the client has disabled push or reset the push before it has been sent.

      The `handler` may be queued if the client has reduced the maximum number of streams the server can push concurrently.

      Push can be sent only for peer initiated streams and if the response is not ended.
      Parameters:
        `method` - the method of the promised request
        `host` - the host of the promised request
        `path` - the path of the promised request
        `headers` - the headers of the promised request
        `handler` - the handler notified when the response can be written
      Returns:
        a reference to this, so the API can be used fluently

    - #### pushObservable

          public Observable<HttpServerResponse> pushObservable(HttpMethod method,
                                                               String host,
                                                               String path,
                                                               MultiMap headers)

      Push a response to the client.

      The `handler` will be notified with a success when the push can be sent and with a failure when the client has disabled push or reset the push before it has been sent.

      The `handler` may be queued if the client has reduced the maximum number of streams the server can push concurrently.

      Push can be sent only for peer initiated streams and if the response is not ended.
      Parameters:
        `method` - the method of the promised request
        `host` - the host of the promised request
        `path` - the path of the promised request
        `headers` - the headers of the promised request
      Returns:

    - #### reset

          public void reset()

      Reset this HTTP/2 stream with the error code `0`.

    - #### reset

          public void reset(long code)

      Reset this HTTP/2 stream with the error `code`.
      Parameters:
        `code` - the error code

    - #### writeCustomFrame

          public HttpServerResponse writeCustomFrame(int type,
                                                     int flags,
                                                     Buffer payload)

      Write an HTTP/2 frame to the response, allowing to extend the HTTP/2 protocol.

      The frame is sent immediatly and is not subject to flow control.

      Parameters:
        `type` - the 8-bit frame type
        `flags` - the 8-bit frame flags
        `payload` - the frame payload
      Returns:
        a reference to this, so the API can be used fluently

    - #### writeCustomFrame

          public HttpServerResponse writeCustomFrame(HttpFrame frame)

      Like `writeCustomFrame(int, int, io.vertx.rxjava.core.buffer.Buffer)` but with an `HttpFrame`.
      Parameters:
        `frame` - the frame to write
      Returns:

    - #### newInstance

          public static HttpServerResponse newInstance(HttpServerResponse arg)

Copyright © 2016. All rights reserved.