Class: Vertx::HttpServerResponse

Inherits:
Object
  • Object
show all
Includes:
WriteStream
Defined in:
/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb

Overview

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.

Instance Method Summary (collapse)

Instance Method Details

- (self) body_end_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.

Yields:

  • the handler

Returns:

  • (self)

Raises:

  • (ArgumentError)


292
293
294
295
296
297
298
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb', line 292

def body_end_handler
  if block_given?
    @j_del.java_method(:bodyEndHandler, [Java::IoVertxCore::Handler.java_class]).call(Proc.new { yield })
    return self
  end
  raise ArgumentError, "Invalid arguments when calling body_end_handler()"
end

- (true, false) chunked?

@return is the response chunked?

Returns:

  • (true, false)

Raises:

  • (ArgumentError)


154
155
156
157
158
159
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb', line 154

def chunked?
  if !block_given?
    return @j_del.java_method(:isChunked, []).call()
  end
  raise ArgumentError, "Invalid arguments when calling chunked?()"
end

- (void) close

This method returns an undefined value.

Close the underlying TCP connection corresponding to the request.

Raises:

  • (ArgumentError)


254
255
256
257
258
259
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb', line 254

def close
  if !block_given?
    return @j_del.java_method(:close, []).call()
  end
  raise ArgumentError, "Invalid arguments when calling close()"
end

- (self) close_handler { ... }

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

Yields:

  • the handler

Returns:

  • (self)

Raises:

  • (ArgumentError)


208
209
210
211
212
213
214
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb', line 208

def close_handler
  if block_given?
    @j_del.java_method(:closeHandler, [Java::IoVertxCore::Handler.java_class]).call(Proc.new { yield })
    return self
  end
  raise ArgumentError, "Invalid arguments when calling close_handler()"
end

- (self) drain_handler { ... }

Yields:

Returns:

  • (self)

Raises:

  • (ArgumentError)


87
88
89
90
91
92
93
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb', line 87

def drain_handler
  if block_given?
    @j_del.java_method(:drainHandler, [Java::IoVertxCore::Handler.java_class]).call(Proc.new { yield })
    return self
  end
  raise ArgumentError, "Invalid arguments when calling drain_handler()"
end

- (void) end - (void) end(chunk) - (void) end(chunk) - (void) end(chunk, enc)

This method returns an undefined value.

Same as #end but writes a String with the specified encoding before ending the response.

Overloads:

  • - (void) end(chunk)

    Parameters:

    • chunk (String)
      the string to write before ending the response
  • - (void) end(chunk)

    Parameters:

    • chunk (::Vertx::Buffer)
      the buffer to write before ending the response
  • - (void) end(chunk, enc)

    Parameters:

    • chunk (String)
      the string to write before ending the response
    • enc (String)
      the encoding to use

Raises:

  • (ArgumentError)


225
226
227
228
229
230
231
232
233
234
235
236
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb', line 225

def end(param_1=nil,param_2=nil)
  if !block_given? && param_1 == nil && param_2 == nil
    return @j_del.java_method(:end, []).call()
  elsif param_1.class == String && !block_given? && param_2 == nil
    return @j_del.java_method(:end, [Java::java.lang.String.java_class]).call(param_1)
  elsif param_1.class.method_defined?(:j_del) && !block_given? && param_2 == nil
    return @j_del.java_method(:end, [Java::IoVertxCoreBuffer::Buffer.java_class]).call(param_1.j_del)
  elsif param_1.class == String && param_2.class == String && !block_given?
    return @j_del.java_method(:end, [Java::java.lang.String.java_class,Java::java.lang.String.java_class]).call(param_1,param_2)
  end
  raise ArgumentError, "Invalid arguments when calling end(param_1,param_2)"
end

- (true, false) ended?

@return has the response already ended?

Returns:

  • (true, false)

Raises:

  • (ArgumentError)


262
263
264
265
266
267
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb', line 262

def ended?
  if !block_given?
    return @j_del.java_method(:ended, []).call()
  end
  raise ArgumentError, "Invalid arguments when calling ended?()"
end

- (self) exception_handler { ... }

Yields:

Returns:

  • (self)

Raises:

  • (ArgumentError)


47
48
49
50
51
52
53
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb', line 47

def exception_handler
  if block_given?
    @j_del.java_method(:exceptionHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(event) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling exception_handler()"
end

- (Fixnum) get_status_code

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

Returns:

  • (Fixnum)

Raises:

  • (ArgumentError)


96
97
98
99
100
101
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb', line 96

def get_status_code
  if !block_given?
    return @j_del.java_method(:getStatusCode, []).call()
  end
  raise ArgumentError, "Invalid arguments when calling get_status_code()"
end

- (String) get_status_message

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

Returns:

  • (String)

Raises:

  • (ArgumentError)


116
117
118
119
120
121
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb', line 116

def get_status_message
  if !block_given?
    return @j_del.java_method(:getStatusMessage, []).call()
  end
  raise ArgumentError, "Invalid arguments when calling get_status_message()"
end

- (true, false) head_written?

@return have the headers for the response already been written?

Returns:

  • (true, false)

Raises:

  • (ArgumentError)


270
271
272
273
274
275
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb', line 270

def head_written?
  if !block_given?
    return @j_del.java_method(:headWritten, []).call()
  end
  raise ArgumentError, "Invalid arguments when calling head_written?()"
end

- (::Vertx::MultiMap) headers

@return The HTTP headers

Returns:

Raises:

  • (ArgumentError)


162
163
164
165
166
167
168
169
170
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb', line 162

def headers
  if !block_given?
    if @cached_headers != nil
      return @cached_headers
    end
    return @cached_headers = ::Vertx::MultiMap.new(@j_del.java_method(:headers, []).call())
  end
  raise ArgumentError, "Invalid arguments when calling headers()"
end

- (self) headers_end_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.

Yields:

  • the handler

Returns:

  • (self)

Raises:

  • (ArgumentError)


280
281
282
283
284
285
286
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb', line 280

def headers_end_handler
  if block_given?
    @j_del.java_method(:headersEndHandler, [Java::IoVertxCore::Handler.java_class]).call(Proc.new { yield })
    return self
  end
  raise ArgumentError, "Invalid arguments when calling headers_end_handler()"
end

- (self) put_header(name = nil, value = nil)

Put an HTTP header

Parameters:

  • name (String) (defaults to: nil)
    the header name
  • value (String) (defaults to: nil)
    the header value.

Returns:

  • (self)

Raises:

  • (ArgumentError)


175
176
177
178
179
180
181
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb', line 175

def put_header(name=nil,value=nil)
  if name.class == String && value.class == String && !block_given?
    @j_del.java_method(:putHeader, [Java::java.lang.String.java_class,Java::java.lang.String.java_class]).call(name,value)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling put_header(name,value)"
end

- (self) put_trailer(name = nil, value = nil)

Put an HTTP trailer

Parameters:

  • name (String) (defaults to: nil)
    the trailer name
  • value (String) (defaults to: nil)
    the trailer value

Returns:

  • (self)

Raises:

  • (ArgumentError)


197
198
199
200
201
202
203
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb', line 197

def put_trailer(name=nil,value=nil)
  if name.class == String && value.class == String && !block_given?
    @j_del.java_method(:putTrailer, [Java::java.lang.String.java_class,Java::java.lang.String.java_class]).call(name,value)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling put_trailer(name,value)"
end

- (self) send_file(filename = nil) { ... }

Like #send_file but providing a handler which will be notified once the file has been completely written to the wire.

Parameters:

  • filename (String) (defaults to: nil)
    path to the file to serve

Yields:

  • handler that will be called on completion

Returns:

  • (self)

Raises:

  • (ArgumentError)


242
243
244
245
246
247
248
249
250
251
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb', line 242

def send_file(filename=nil)
  if filename.class == String && !block_given?
    @j_del.java_method(:sendFile, [Java::java.lang.String.java_class]).call(filename)
    return self
  elsif filename.class == String && block_given?
    @j_del.java_method(:sendFile, [Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(filename,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling send_file(filename)"
end

- (self) set_chunked(chunked = nil)

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 (true, false) (defaults to: nil)

Returns:

  • (self)

Raises:

  • (ArgumentError)


145
146
147
148
149
150
151
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb', line 145

def set_chunked(chunked=nil)
  if (chunked.class == TrueClass || chunked.class == FalseClass) && !block_given?
    @j_del.java_method(:setChunked, [Java::boolean.java_class]).call(chunked)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling set_chunked(chunked)"
end

- (self) set_status_code(statusCode = nil)

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 (Fixnum) (defaults to: nil)

Returns:

  • (self)

Raises:

  • (ArgumentError)


106
107
108
109
110
111
112
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb', line 106

def set_status_code(statusCode=nil)
  if statusCode.class == Fixnum && !block_given?
    @j_del.java_method(:setStatusCode, [Java::int.java_class]).call(statusCode)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling set_status_code(statusCode)"
end

- (self) set_status_message(statusMessage = nil)

Set the status message

Parameters:

  • statusMessage (String) (defaults to: nil)

Returns:

  • (self)

Raises:

  • (ArgumentError)


125
126
127
128
129
130
131
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb', line 125

def set_status_message(statusMessage=nil)
  if statusMessage.class == String && !block_given?
    @j_del.java_method(:setStatusMessage, [Java::java.lang.String.java_class]).call(statusMessage)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling set_status_message(statusMessage)"
end

- (self) set_write_queue_max_size(maxSize = nil)

Parameters:

  • maxSize (Fixnum) (defaults to: nil)

Returns:

  • (self)

Raises:

  • (ArgumentError)


78
79
80
81
82
83
84
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb', line 78

def set_write_queue_max_size(maxSize=nil)
  if maxSize.class == Fixnum && !block_given?
    @j_del.java_method(:setWriteQueueMaxSize, [Java::int.java_class]).call(maxSize)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling set_write_queue_max_size(maxSize)"
end

- (::Vertx::MultiMap) trailers

@return The HTTP trailers

Returns:

Raises:

  • (ArgumentError)


184
185
186
187
188
189
190
191
192
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb', line 184

def trailers
  if !block_given?
    if @cached_trailers != nil
      return @cached_trailers
    end
    return @cached_trailers = ::Vertx::MultiMap.new(@j_del.java_method(:trailers, []).call())
  end
  raise ArgumentError, "Invalid arguments when calling trailers()"
end

- (self) write(data) - (self) write(chunk) - (self) write(chunk, enc)

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

Overloads:

  • - (self) write(data)

    Parameters:

  • - (self) write(chunk)

    Parameters:

    • chunk (String)
      the string to write
  • - (self) write(chunk, enc)

    Parameters:

    • chunk (String)
      the string to write
    • enc (String)
      the encoding to use

Returns:

  • (self)

Raises:

  • (ArgumentError)


63
64
65
66
67
68
69
70
71
72
73
74
75
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb', line 63

def write(param_1=nil,param_2=nil)
  if param_1.class.method_defined?(:j_del) && !block_given? && param_2 == nil
    @j_del.java_method(:write, [Java::IoVertxCoreBuffer::Buffer.java_class]).call(param_1.j_del)
    return self
  elsif param_1.class == String && !block_given? && param_2 == nil
    @j_del.java_method(:write, [Java::java.lang.String.java_class]).call(param_1)
    return self
  elsif param_1.class == String && param_2.class == String && !block_given?
    @j_del.java_method(:write, [Java::java.lang.String.java_class,Java::java.lang.String.java_class]).call(param_1,param_2)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling write(param_1,param_2)"
end

- (true, false) write_queue_full?

This will return true if there are more bytes in the write queue than the value set using #set_write_queue_max_size

Returns:

  • (true, false)
    true if write queue is full

Raises:

  • (ArgumentError)


39
40
41
42
43
44
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server_response.rb', line 39

def write_queue_full?
  if !block_given?
    return @j_del.java_method(:writeQueueFull, []).call()
  end
  raise ArgumentError, "Invalid arguments when calling write_queue_full?()"
end