Class List Method List File List

# Class: Vertx::HttpClientRequest

Inherits:
  Object
  - Object
  - Vertx::HttpClientRequest
  show all
Includes:
  ReadStream, WriteStream
Defined in:
  /Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_client_request.rb

## Overview

Represents a client-side HTTP request.

Instances are created by an HttpClient instance, via one of the methods corresponding to the specific HTTP methods, or the generic request methods. On creation the request will not have been written to the wire.

Once a request has been obtained, headers can be set on it, and data can be written to its body if required. Once you are ready to send the request, one of the #end methods should be called.

Nothing is actually sent until the request has been internally assigned an HTTP connection.

The HttpClient instance will return an instance of this class immediately, even if there are no HTTP connections available in the pool. Any requests sent before a connection is assigned will be queued internally and actually sent when an HTTP connection becomes available from the pool.

The headers of the request are queued for writing either when the #end method is called, or, when the first part of the body is written, whichever occurs first.

This class supports both chunked and non-chunked HTTP.

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

An example of using this class is as follows:

## Instance Method Summary (collapse)

- - (true, false) chunked?
  @return Is the request chunked?.
- - (self) continue_handler { ... }
  If you send an HTTP request with the header Expect set to the value 100-continue and the server responds with an interim HTTP response with a status code of 100 and a continue handler has been set using this method, then the handler will be called.
- - (self) drain_handler { ... }
- - (void) end(param_1 = nil, param_2 = nil)
  Same as #end but writes a String with the specified encoding.
- - (self) end_handler { ... }
- - (self) exception_handler { ... }
- - (self) handler { ... }
- - (::Vertx::MultiMap) headers
  @return The HTTP headers.
- - (:OPTIONS, ...) method
  The HTTP method for the request.
- - (self) pause
- - (self) put_header(name = nil, value = nil)
  Put an HTTP header.
- - (self) resume
- - (self) send_head
  Forces the head of the request to be written before #end is called on the request or any data is written to it.
- - (self) set_chunked(chunked = nil)
  If chunked is true then the request will be set into HTTP chunked mode.
- - (self) set_timeout(timeoutMs = nil)
  Set's the amount of time after which if a response is not received TimeoutException will be sent to the exception handler of this request.
- - (self) set_write_queue_max_size(maxSize = nil)
- - (String) uri
  @return The URI of the request.
- - (self) write(param_1 = nil, param_2 = nil)
  Write a String to the request body, encoded using the encoding enc.
- - (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.

## Instance Method Details

### - (`true`, `false`) chunked?

@return Is the request chunked?

Returns:

- (`true`, `false`)

Raises:

- (`ArgumentError`)

    150
    151
    152
    153
    154
    155
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_client_request.rb', line 150

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

### - (`self`) continue_handler { ... }

If you send an HTTP request with the header `Expect` set to the value `100-continue` and the server responds with an interim HTTP response with a status code of `100` and a continue handler has been set using this method, then the `handler` will be called.

You can then continue to write data to the request body and later end it. This is normally used in conjunction with the #send_head method to force the request header to be written before the request has ended.

Yields:

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    202
    203
    204
    205
    206
    207
    208
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_client_request.rb', line 202

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

### - (`self`) drain_handler { ... }

Yields:

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

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

    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

Overloads:

- - (`void`) end(chunk)

  Parameters:

  - chunk (`String`)
- - (`void`) end(chunk)

  Parameters:

  - chunk (`::Vertx::Buffer`)
- - (`void`) end(chunk, enc)

  Parameters:

  - chunk (`String`)
  - enc (`String`)

Raises:

- (`ArgumentError`)

    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_client_request.rb', line 232

    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

### - (`self`) end_handler { ... }

Yields:

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    131
    132
    133
    134
    135
    136
    137
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_client_request.rb', line 131

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

### - (`self`) exception_handler { ... }

Yields:

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    57
    58
    59
    60
    61
    62
    63
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_client_request.rb', line 57

    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

### - (`self`) handler { ... }

Yields:

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_client_request.rb', line 106

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

### - (`::Vertx::MultiMap`) headers

@return The HTTP headers

Returns:

- (`::Vertx::MultiMap`)

Raises:

- (`ArgumentError`)

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

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

### - (`:OPTIONS`, ...) method

The HTTP method for the request.

Returns:

- (`:OPTIONS`, `:GET`, `:HEAD`, `:POST`, `:PUT`, `:DELETE`, `:TRACE`, `:CONNECT`, `:PATCH`)

Raises:

- (`ArgumentError`)

    158
    159
    160
    161
    162
    163
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_client_request.rb', line 158

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

### - (`self`) pause

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

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

    def pause
      if !block_given?
        @j_del.java_method(:pause, []).call()
        return self
      end
      raise ArgumentError, "Invalid arguments when calling pause()"
    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`)

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

    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`) resume

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    122
    123
    124
    125
    126
    127
    128
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_client_request.rb', line 122

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

### - (`self`) send_head

Forces the head of the request to be written before #end is called on the request or any data is written to it.

This is normally used to implement HTTP 100-continue handling, see #continue_handler for more information.

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    215
    216
    217
    218
    219
    220
    221
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_client_request.rb', line 215

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

### - (`self`) set_chunked(chunked = nil)

If chunked is true then the request will be set into HTTP chunked mode

Parameters:

- chunked (`true`, `false`) (defaults to: `nil`) —
  true if chunked encoding

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    141
    142
    143
    144
    145
    146
    147
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_client_request.rb', line 141

    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_timeout(timeoutMs = nil)

Set's the amount of time after which if a response is not received TimeoutException will be sent to the exception handler of this request.

Calling this method more than once has the effect of canceling any existing timeout and starting the timeout from scratch.

Parameters:

- timeoutMs (`Fixnum`) (defaults to: `nil`) —
  The quantity of time in milliseconds.

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    251
    252
    253
    254
    255
    256
    257
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_client_request.rb', line 251

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

### - (`self`) set_write_queue_max_size(maxSize = nil)

Parameters:

- maxSize (`Fixnum`) (defaults to: `nil`)

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

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

    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

### - (`String`) uri

@return The URI of the request.

Returns:

- (`String`)

Raises:

- (`ArgumentError`)

    166
    167
    168
    169
    170
    171
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_client_request.rb', line 166

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

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

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

Overloads:

- - (`self`) write(data)

  Parameters:

  - data (`::Vertx::Buffer`)
- - (`self`) write(chunk)

  Parameters:

  - chunk (`String`)
- - (`self`) write(chunk, enc)

  Parameters:

  - chunk (`String`)
  - enc (`String`)

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_client_request.rb', line 73

    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`)

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

    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