vertx-lang-scala-docs_2.12 3.9.0 API < Back
 

# Packages

-  package root
  Definition Classes
    root
-  package io
  Definition Classes
    root
-  package vertx
  Definition Classes
    io
-  package scala
  Definition Classes
    vertx
-  package core
  Definition Classes
    scala
-  package http
  Definition Classes
    core
- Cookie
- GoAway
- Http2Settings
- HttpClient
- HttpClientOptions
- HttpClientRequest
- HttpClientResponse
- HttpConnection
- HttpFrame
- HttpServer
- HttpServerFileUpload
- HttpServerOptions
- HttpServerRequest
- HttpServerResponse
- RequestOptions
- ServerWebSocket
- StreamPriority
- WebSocket
- WebSocketBase
- WebSocketConnectOptions
- WebSocketFrame

c

io.vertx.scala.core.http

# HttpServerResponse 

###
Companion object HttpServerResponse

#### class HttpServerResponse extends WriteStream[Buffer]

Represents a server-side HTTP response.

An instance of this is created and associated to every instance of io.vertx.scala.core.http.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 io.vertx.scala.core.streams.WriteStream so it can be used with io.vertx.scala.core.streams.Pump to pump data with flow control.

Linear Supertypes
WriteStream[Buffer], StreamBase, AnyRef, Any
 
Ordering

1. Alphabetic
2. By Inheritance

Inherited

1. HttpServerResponse
2. WriteStream
3. StreamBase
4. AnyRef
5. Any

1. Hide All
2. Show All

Visibility

1. Public
2. All

### Instance Constructors

1.  new HttpServerResponse(_asJava: AnyRef)

### Value Members

1.  final def !=(arg0: Any): Boolean
   Definition Classes
     AnyRef → Any
2.  final def ##(): Int
   Definition Classes
     AnyRef → Any
3.  final def ==(arg0: Any): Boolean
   Definition Classes
     AnyRef → Any
4.  def addCookie(cookie: Cookie): HttpServerResponse

   Add a cookie.

   Add a cookie. This will be sent back to the client in the response. * @param cookie the cookie

   returns

     a reference to this, so the API can be used fluently

5.  final def asInstanceOf[T0]: T0
   Definition Classes
     Any
6.  def asJava: AnyRef
   Definition Classes
     HttpServerResponse → WriteStream → StreamBase
7.  def bodyEndHandler(handler: Handler[Unit]): HttpServerResponse

   Provides a handler that will be called after the last part of the body is written to the wire.

   Provides a handler that will be called after the last part of the body is written to the wire. The handler is called asynchronously of when the response has been received by the client. This provides a hook allowing you to do more operations once the request has been sent over the wire such as resource cleanup. * @param handler the handler

   returns

     a reference to this, so the API can be used fluently

8.  def bytesWritten(): Long

   returns

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

9.  def clone(): AnyRef
   Attributes
     protected[java.lang]
   Definition Classes
     AnyRef
   Annotations
     @native() @throws( ... )
10.  def close(): Unit

    Close the underlying TCP connection corresponding to the request.

11.  def closeHandler(handler: Handler[Unit]): HttpServerResponse

    Set a close handler for the response, this is called when the underlying connection is closed and the response was still using the connection.

    Set a close handler for the response, this is called when the underlying connection is closed and the response was still using the connection.

    For HTTP/1.x it is called when the connection is closed before `end()` is called, therefore it is not guaranteed to be called.

    For HTTP/2 it is called when the related stream is closed, and therefore it will be always be called. * @param handler the handler

    returns

      a reference to this, so the API can be used fluently

12.  def closed(): Boolean

    returns

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

13.  def drainHandler(handler: Handler[Unit]): HttpServerResponse

    Set a drain handler on the stream.

    Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write queue is ready to accept buffers again. See io.vertx.scala.core.streams.Pump for an example of this being used.

    The stream implementation defines when the drain handler, for example it could be when the queue size has been reduced to `maxSize / 2`. * @param handler the handler

    returns

      a reference to this, so the API can be used fluently

    Definition Classes
      HttpServerResponse → WriteStream
14.  def end(): Unit

    Ends the response.

    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.

    Definition Classes
      HttpServerResponse → WriteStream
15.  def end(chunk: Buffer, handler: Handler[AsyncResult[Unit]]): Unit

    Same as io.vertx.scala.core.http.HttpServerResponse#end but with an `handler` called when the operation completes

    Same as io.vertx.scala.core.http.HttpServerResponse#end but with an `handler` called when the operation completes

    Definition Classes
      HttpServerResponse → WriteStream
16.  def end(chunk: Buffer): Unit

    Same as io.vertx.scala.core.http.HttpServerResponse#end but writes some data to the response body before ending.

    Same as io.vertx.scala.core.http.HttpServerResponse#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. * @param chunk the buffer to write before ending the response

    Definition Classes
      HttpServerResponse → WriteStream
17.  def end(chunk: String, enc: String, handler: Handler[AsyncResult[Unit]]): Unit

    Same as io.vertx.scala.core.http.HttpServerResponse#end but with an `handler` called when the operation completes

18.  def end(chunk: String, enc: String): Unit

    Same as io.vertx.scala.core.http.HttpServerResponse#end but writes a String with the specified encoding before ending the response.

    Same as io.vertx.scala.core.http.HttpServerResponse#end but writes a String with the specified encoding before ending the response. * @param chunk the string to write before ending the response

    enc

      the encoding to use

19.  def end(chunk: String, handler: Handler[AsyncResult[Unit]]): Unit

    Same as io.vertx.scala.core.http.HttpServerResponse#end but with an `handler` called when the operation completes

20.  def end(chunk: String): Unit

    Same as io.vertx.scala.core.http.HttpServerResponse#end but writes a String in UTF-8 encoding before ending the response.

    Same as io.vertx.scala.core.http.HttpServerResponse#end but writes a String in UTF-8 encoding before ending the response. * @param chunk the string to write before ending the response

21.  def end(handler: Handler[AsyncResult[Unit]]): Unit

    Same as io.vertx.scala.core.http.HttpServerResponse#end but with an `handler` called when the operation completes

    Same as io.vertx.scala.core.http.HttpServerResponse#end but with an `handler` called when the operation completes

    Definition Classes
      HttpServerResponse → WriteStream
22.  def endFuture(chunk: Buffer): scala.concurrent.Future[Unit]

    Like end but returns a scala.concurrent.Future instead of taking an AsyncResultHandler.

    Like end but returns a scala.concurrent.Future instead of taking an AsyncResultHandler.

    Definition Classes
      HttpServerResponse → WriteStream
23.  def endFuture(chunk: String, enc: String): scala.concurrent.Future[Unit]

    Like end but returns a scala.concurrent.Future instead of taking an AsyncResultHandler.

24.  def endFuture(chunk: String): scala.concurrent.Future[Unit]

    Like end but returns a scala.concurrent.Future instead of taking an AsyncResultHandler.

25.  def endFuture(): scala.concurrent.Future[Unit]

    Like end but returns a scala.concurrent.Future instead of taking an AsyncResultHandler.

    Like end but returns a scala.concurrent.Future instead of taking an AsyncResultHandler.

    Definition Classes
      HttpServerResponse → WriteStream
26.  def endHandler(handler: Handler[Unit]): HttpServerResponse

    Set an end handler for the response.

    Set an end handler for the response. This will be called when the response is disposed to allow consistent cleanup of the response. * @param handler the handler

    returns

      a reference to this, so the API can be used fluently

27.  def ended(): Boolean

    returns

      has the response already ended?

28.  final def eq(arg0: AnyRef): Boolean
    Definition Classes
      AnyRef
29.  def equals(arg0: Any): Boolean
    Definition Classes
      AnyRef → Any
30.  def exceptionHandler(handler: Handler[Throwable]): HttpServerResponse

    Set an exception handler on the write stream.

    Set an exception handler on the write stream. * @param handler the exception handler

    returns

      a reference to this, so the API can be used fluently

    Definition Classes
      HttpServerResponse → WriteStream → StreamBase
31.  def finalize(): Unit
    Attributes
      protected[java.lang]
    Definition Classes
      AnyRef
    Annotations
      @throws( classOf[java.lang.Throwable] )
32.  final def getClass(): Class[_]
    Definition Classes
      AnyRef → Any
    Annotations
      @native()
33.  def getStatusCode(): Int

    returns

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

34.  def getStatusMessage(): String

    returns

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

35.  def hashCode(): Int
    Definition Classes
      AnyRef → Any
    Annotations
      @native()
36.  def headWritten(): Boolean

    returns

      have the headers for the response already been written?

37.  def headers(): MultiMap

    returns

      The HTTP headers

38.  def headersEndHandler(handler: Handler[Unit]): HttpServerResponse

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

    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. * @param handler the handler

    returns

      a reference to this, so the API can be used fluently

39.  def isChunked(): Boolean

    returns

      is the response chunked?

40.  final def isInstanceOf[T0]: Boolean
    Definition Classes
      Any
41.  final def ne(arg0: AnyRef): Boolean
    Definition Classes
      AnyRef
42.  final def notify(): Unit
    Definition Classes
      AnyRef
    Annotations
      @native()
43.  final def notifyAll(): Unit
    Definition Classes
      AnyRef
    Annotations
      @native()
44.  def push(method: HttpMethod, host: String, path: String, headers: MultiMap, handler: Handler[AsyncResult[HttpServerResponse]]): HttpServerResponse

    Push a response to the client.

    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. * @param 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

45.  def push(method: HttpMethod, path: String, handler: Handler[AsyncResult[HttpServerResponse]]): HttpServerResponse

    Like io.vertx.scala.core.http.HttpServerResponse#push with the host copied from the current request.

46.  def push(method: HttpMethod, path: String, headers: MultiMap, handler: Handler[AsyncResult[HttpServerResponse]]): HttpServerResponse

    Like io.vertx.scala.core.http.HttpServerResponse#push with the host copied from the current request.

47.  def push(method: HttpMethod, host: String, path: String, handler: Handler[AsyncResult[HttpServerResponse]]): HttpServerResponse

    Like io.vertx.scala.core.http.HttpServerResponse#push with no headers.

48.  def pushFuture(method: HttpMethod, host: String, path: String, headers: MultiMap): scala.concurrent.Future[HttpServerResponse]

    Like push but returns a scala.concurrent.Future instead of taking an AsyncResultHandler.

49.  def pushFuture(method: HttpMethod, path: String): scala.concurrent.Future[HttpServerResponse]

    Like push but returns a scala.concurrent.Future instead of taking an AsyncResultHandler.

50.  def pushFuture(method: HttpMethod, path: String, headers: MultiMap): scala.concurrent.Future[HttpServerResponse]

    Like push but returns a scala.concurrent.Future instead of taking an AsyncResultHandler.

51.  def pushFuture(method: HttpMethod, host: String, path: String): scala.concurrent.Future[HttpServerResponse]

    Like push but returns a scala.concurrent.Future instead of taking an AsyncResultHandler.

52.  def putHeader(name: String, value: String): HttpServerResponse

    Put an HTTP header * @param name the header name

    Put an HTTP header * @param name the header name

    value

      the header value.

    returns

      a reference to this, so the API can be used fluently

53.  def putTrailer(name: String, value: String): HttpServerResponse

    Put an HTTP trailer * @param name the trailer name

    Put an HTTP trailer * @param name the trailer name

    value

      the trailer value

    returns

      a reference to this, so the API can be used fluently

54.  def removeCookie(name: String, invalidate: Boolean): Option[Cookie]

    Remove a cookie from the cookie set.

    Remove a cookie from the cookie set. If invalidate is true then it will expire a cookie, notifying a User Agent to remove it from its cookie jar. * @param name the name of the cookie

    returns

      the cookie, if it existed, or null

55.  def removeCookie(name: String): Option[Cookie]

    Expire a cookie, notifying a User Agent to remove it from its cookie jar.

    Expire a cookie, notifying a User Agent to remove it from its cookie jar. * @param name the name of the cookie

    returns

      the cookie, if it existed, or null

56.  def reset(code: Long): Unit

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

    Reset this HTTP/2 stream with the error `code`. * @param code the error code

57.  def reset(): Unit

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

58.  def sendFile(filename: String, offset: Long, length: Long, resultHandler: Handler[AsyncResult[Unit]]): HttpServerResponse

    Like io.vertx.scala.core.http.HttpServerResponse#sendFile but providing a handler which will be notified once the file has been completely written to the wire.

    Like io.vertx.scala.core.http.HttpServerResponse#sendFile but providing a handler which will be notified once the file has been completely written to the wire. * @param 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

59.  def sendFile(filename: String, offset: Long, resultHandler: Handler[AsyncResult[Unit]]): HttpServerResponse

    Like io.vertx.scala.core.http.HttpServerResponse#sendFile but providing a handler which will be notified once the file has been completely written to the wire.

    Like io.vertx.scala.core.http.HttpServerResponse#sendFile but providing a handler which will be notified once the file has been completely written to the wire. * @param 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

60.  def sendFile(filename: String, resultHandler: Handler[AsyncResult[Unit]]): HttpServerResponse

    Like io.vertx.scala.core.http.HttpServerResponse#sendFile but providing a handler which will be notified once the file has been completely written to the wire.

    Like io.vertx.scala.core.http.HttpServerResponse#sendFile but providing a handler which will be notified once the file has been completely written to the wire. * @param 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

61.  def sendFile(filename: String, offset: Long, length: Long): HttpServerResponse

    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.

    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. * @param filename path to the file to serve

    offset

      offset to start serving from

    length

      the number of bytes to send

    returns

      a reference to this, so the API can be used fluently

62.  def sendFile(filename: String, offset: Long): HttpServerResponse

    Same as io.vertx.scala.core.http.HttpServerResponse#sendFile using length `Long.MAX_VALUE` which means until the end of the file.

    Same as io.vertx.scala.core.http.HttpServerResponse#sendFile using length `Long.MAX_VALUE` which means until the end of the file. * @param 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

63.  def sendFile(filename: String): HttpServerResponse

    Same as io.vertx.scala.core.http.HttpServerResponse#sendFile using offset `0` which means starting from the beginning of the file.

    Same as io.vertx.scala.core.http.HttpServerResponse#sendFile using offset `0` which means starting from the beginning of the file. * @param filename path to the file to serve

    returns

      a reference to this, so the API can be used fluently

64.  def sendFileFuture(filename: String, offset: Long, length: Long): scala.concurrent.Future[Unit]

    Like sendFile but returns a scala.concurrent.Future instead of taking an AsyncResultHandler.

65.  def sendFileFuture(filename: String, offset: Long): scala.concurrent.Future[Unit]

    Like sendFile but returns a scala.concurrent.Future instead of taking an AsyncResultHandler.

66.  def sendFileFuture(filename: String): scala.concurrent.Future[Unit]

    Like sendFile but returns a scala.concurrent.Future instead of taking an AsyncResultHandler.

67.  def setChunked(chunked: Boolean): HttpServerResponse

    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` 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. * @return a reference to this, so the API can be used fluently

68.  def setStatusCode(statusCode: Int): HttpServerResponse

    Set the status code.

    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. * @return a reference to this, so the API can be used fluently

69.  def setStatusMessage(statusMessage: String): HttpServerResponse

    Set the status message * @return a reference to this, so the API can be used fluently

70.  def setStreamPriority(streamPriority: StreamPriority): HttpServerResponse

    Sets the priority of the associated stream

    Sets the priority of the associated stream

    This is not implemented for HTTP/1.x. * @param streamPriority the priority for this request's stream see StreamPriority

71.  def setWriteQueueMaxSize(maxSize: Int): HttpServerResponse

    Set the maximum size of the write queue to `maxSize`.

    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` items in the write queue. This is used as an indicator by classes such as `Pump` to provide flow control.

    The value is defined by the implementation of the stream, e.g in bytes for a io.vertx.scala.core.net.NetSocket, the number of io.vertx.scala.core.eventbus.Message for a io.vertx.scala.core.eventbus.MessageProducer, etc... * @param maxSize the max size of the write stream

    returns

      a reference to this, so the API can be used fluently

    Definition Classes
      HttpServerResponse → WriteStream
72.  def streamId(): Int

    returns

      the id of the stream of this response, `-1` for HTTP/1.x

73.  final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
      AnyRef
74.  def toString(): String
    Definition Classes
      AnyRef → Any
75.  def trailers(): MultiMap

    returns

      The HTTP trailers

76.  final def wait(): Unit
    Definition Classes
      AnyRef
    Annotations
      @throws( ... )
77.  final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
      AnyRef
    Annotations
      @throws( ... )
78.  final def wait(arg0: Long): Unit
    Definition Classes
      AnyRef
    Annotations
      @native() @throws( ... )
79.  def write(chunk: String, handler: Handler[AsyncResult[Unit]]): HttpServerResponse

    Same as io.vertx.scala.core.http.HttpServerResponse#write but with an `handler` called when the operation completes

80.  def write(chunk: String): HttpServerResponse

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

    Write a String to the response body, encoded in UTF-8. * @param chunk the string to write

    returns

      a reference to this, so the API can be used fluently

81.  def write(chunk: String, enc: String, handler: Handler[AsyncResult[Unit]]): HttpServerResponse

    Same as io.vertx.scala.core.http.HttpServerResponse#write but with an `handler` called when the operation completes

82.  def write(chunk: String, enc: String): HttpServerResponse

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

    Write a String to the response body, encoded using the encoding `enc`. * @param chunk the string to write

    enc

      the encoding to use

    returns

      a reference to this, so the API can be used fluently

83.  def write(data: Buffer, handler: Handler[AsyncResult[Unit]]): HttpServerResponse

    Same as io.vertx.scala.core.http.HttpServerResponse#write but with an `handler` called when the operation completes

    Same as io.vertx.scala.core.http.HttpServerResponse#write but with an `handler` called when the operation completes

    Definition Classes
      HttpServerResponse → WriteStream
84.  def write(data: Buffer): HttpServerResponse

    Write some data to the stream.

    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 io.vertx.scala.core.streams.WriteStream#writeQueueFull method before writing. This is done automatically if using a io.vertx.scala.core.streams.Pump. * @param data the data to write

    returns

      a reference to this, so the API can be used fluently

    Definition Classes
      HttpServerResponse → WriteStream
85.  def writeContinue(): HttpServerResponse

    Used to write an interim 100 Continue response to signify that the client should send the rest of the request.

    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 * @return a reference to this, so the API can be used fluently

86.  def writeCustomFrame(frame: HttpFrame): HttpServerResponse

    Like io.vertx.scala.core.http.HttpServerResponse#writeCustomFrame but with an io.vertx.scala.core.http.HttpFrame.

    Like io.vertx.scala.core.http.HttpServerResponse#writeCustomFrame but with an io.vertx.scala.core.http.HttpFrame. * @param frame the frame to write

87.  def writeCustomFrame(type: Int, flags: Int, payload: Buffer): HttpServerResponse

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

    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. * @param 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

88.  def writeFuture(chunk: String): scala.concurrent.Future[Unit]

    Like write but returns a scala.concurrent.Future instead of taking an AsyncResultHandler.

89.  def writeFuture(chunk: String, enc: String): scala.concurrent.Future[Unit]

    Like write but returns a scala.concurrent.Future instead of taking an AsyncResultHandler.

90.  def writeFuture(data: Buffer): scala.concurrent.Future[Unit]

    Like write but returns a scala.concurrent.Future instead of taking an AsyncResultHandler.

    Like write but returns a scala.concurrent.Future instead of taking an AsyncResultHandler.

    Definition Classes
      HttpServerResponse → WriteStream
91.  def writeQueueFull(): Boolean

    This will return `true` if there are more bytes in the write queue than the value set using io.vertx.scala.core.http.HttpServerResponse#setWriteQueueMaxSize * @return true if write queue is full

    This will return `true` if there are more bytes in the write queue than the value set using io.vertx.scala.core.http.HttpServerResponse#setWriteQueueMaxSize * @return true if write queue is full

    Definition Classes
      HttpServerResponse → WriteStream

### Inherited from WriteStream[Buffer]

### Inherited from StreamBase

### Inherited from AnyRef

### Inherited from Any

### Ungrouped