Class: Vertx::HttpClient

Inherits:
Object
  • Object
show all
Includes:
ClientSSLSupport, SSLSupport, TCPSupport
Defined in:
src/main/api_shim/core/http.rb

Overview

An HTTP client. A client maintains a pool of connections to a specific host, at a specific port. The HTTP connections can act as pipelines for HTTP requests. It is used as a factory for HttpClientRequest instances which encapsulate the actual HTTP requests. It is also used as a factory for WebSockets.

Author:

Instance Method Summary (collapse)

Methods included from SSLSupport

#key_store_password, #key_store_password=, #key_store_path, #key_store_path=, #ssl, #ssl=, #trust_store_password, #trust_store_password=, #trust_store_path, #trust_store_path=

Methods included from ClientSSLSupport

#trust_all, #trust_all=

Methods included from TCPSupport

#receive_buffer_size=, #reuse_address, #reuse_address=, #send_buffer_size, #send_buffer_size=, #send_receive_size, #so_linger, #so_linger=, #tcp_keep_alive, #tcp_keep_alive=, #traffic_class, #traffic_class=, #use_pooled_buffers, #use_pooled_buffers=

Constructor Details

- (HttpClient) initialize

Create a new HttpClient


92
93
94
# File 'src/main/api_shim/core/http.rb', line 92

def initialize
  @j_del = org.vertx.java.platform.impl.JRubyVerticleFactory.vertx.createHttpClient
end

Instance Method Details

- (Object) close

Close the client. Any unclosed connections will be closed.


291
292
293
# File 'src/main/api_shim/core/http.rb', line 291

def close
  @j_del.close
end

- (Object) connect(uri, &hndlr)

This method returns an Vertx::HttpClientRequest instance which represents an HTTP CONNECT request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.

Parameters:

  • uri. (String)
    A relative URI where to perform the CONNECT on the server.
  • hndlr. (Block)
    The handler to be called with the Vertx::HttpClientResponse


269
270
271
# File 'src/main/api_shim/core/http.rb', line 269

def connect(uri, &hndlr)
  HttpClientRequest.new(@j_del.connect(uri, resp_handler(hndlr)))
end

- (Object) connect_web_socket(uri, &hndlr)

Attempt to connect a WebSocket to the specified URI. The connect is done asynchronously and the handler is called with a WebSocket on success.

Parameters:

  • uri. (String)
    A relative URI where to connect the WebSocket on the host, e.g. /some/path
  • hndlr. (Block)
    The handler to be called with the WebSocket


191
192
193
194
# File 'src/main/api_shim/core/http.rb', line 191

def connect_web_socket(uri, &hndlr)
  @j_del.connectWebsocket(uri) { |j_ws| hndlr.call(WebSocket.new(j_ws)) }
  self
end

- (Object) delete(uri, &hndlr)

This method returns an Vertx::HttpClientRequest instance which represents an HTTP DELETE request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.

Parameters:

  • uri. (String)
    A relative URI where to perform the DELETE on the server.
  • hndlr. (Block)
    The handler to be called with the Vertx::HttpClientResponse


253
254
255
# File 'src/main/api_shim/core/http.rb', line 253

def delete(uri, &hndlr)
  HttpClientRequest.new(@j_del.delete(uri, resp_handler(hndlr)))
end

- (Object) exception_handler(&hndlr)

Set the exception handler.

Parameters:

  • hndlr (Block)
    A block to be used as the handler


98
99
100
101
# File 'src/main/api_shim/core/http.rb', line 98

def exception_handler(&hndlr)
  @j_del.exceptionHandler(hndlr)
  self
end

- (Object) get(uri, &hndlr)

This method returns an Vertx::HttpClientRequest instance which represents an HTTP GET request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.

Parameters:

  • uri. (String)
    A relative URI where to perform the GET on the server.
  • hndlr. (Block)
    The handler to be called with the Vertx::HttpClientResponse


221
222
223
# File 'src/main/api_shim/core/http.rb', line 221

def get(uri, &hndlr)
  HttpClientRequest.new(@j_del.get(uri, resp_handler(hndlr)))
end

- (Object) get_now(uri, headers = nil, &hndlr)

This is a quick version of the #get method where you do not want to do anything with the request before sending. Normally with any of the HTTP methods you create the request then when you are ready to send it you call Vertx::HttpClientRequest#end on it. With this method the request is immediately sent. When an HTTP response is received from the server the handler is called passing in the response.

Parameters:

  • uri. (String)
    A relative URI where to perform the GET on the server.
  • headers. (Hash)
    A Hash of headers to pass with the request.
  • hndlr. (Block)
    The handler to be called with the Vertx::HttpClientResponse


204
205
206
207
# File 'src/main/api_shim/core/http.rb', line 204

def get_now(uri, headers = nil, &hndlr)
  @j_del.getNow(uri, headers, resp_handler(hndlr))
  self
end

- (Object) head(uri, &hndlr)

This method returns an Vertx::HttpClientRequest instance which represents an HTTP HEAD request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.

Parameters:

  • uri. (String)
    A relative URI where to perform the HEAD on the server.
  • hndlr. (Block)
    The handler to be called with the Vertx::HttpClientResponse


229
230
231
# File 'src/main/api_shim/core/http.rb', line 229

def head(uri, &hndlr)
  HttpClientRequest.new(@j_del.head(uri, resp_handler(hndlr)))
end

- (Object) host(val = nil)

Get or set host


168
169
170
171
172
173
174
175
# File 'src/main/api_shim/core/http.rb', line 168

def host(val = nil)
  if val
    @j_del.setHost(val)
    self
  else
    @j_del.getHost
  end
end

- (Object) host=(val)

Set the host name or ip address that the client will attempt to connect to on the server on.

Parameters:

  • host. (String)
    The host name or ip address to connect to.


162
163
164
165
# File 'src/main/api_shim/core/http.rb', line 162

def host=(val)
  @j_del.setHost(val)
  self
end

- (Object) keep_alive(val = nil)

Get or set keep alive


134
135
136
137
138
139
140
141
# File 'src/main/api_shim/core/http.rb', line 134

def keep_alive(val = nil)
  if val
    @j_del.setKeepAlive(val)
    self
  else
    @j_del.isKeepAlive
  end
end

- (Object) keep_alive=(val)

If val is true then, after the request has ended the connection will be returned to the pool where it can be used by another request. In this manner, many HTTP requests can be pipe-lined over an HTTP connection. Keep alive connections will not be closed until the #close method is invoked. If val is false then a new connection will be created for each request and it won't ever go in the pool, the connection will closed after the response has been received. Even with no keep alive, the client will not allow more than #max_pool_size connections to be created at any one time.

Parameters:

  • val. (Boolean)
    The value to use for keep_alive


128
129
130
131
# File 'src/main/api_shim/core/http.rb', line 128

def keep_alive=(val)
  @j_del.setTCPKeepAlive(val)
  self
end

- (Object) max_pool_size(val = nil)

Get or set the max pool size


112
113
114
115
116
117
118
119
# File 'src/main/api_shim/core/http.rb', line 112

def max_pool_size(val = nil)
  if val
    @j_del.setMaxPoolSize(val)
    self
  else
    @j_del.getMaxPoolSize
  end
end

- (Object) max_pool_size=(val)

Set the maximum pool size. The client will maintain up to this number of HTTP connections in an internal pool

Parameters:

  • val. (FixNum)
    The maximum number of connections (default to 1).


106
107
108
109
# File 'src/main/api_shim/core/http.rb', line 106

def max_pool_size=(val)
  @j_del.setMaxPoolSize(val)
  self
end

- (Object) options(uri, &hndlr)

This method returns an Vertx::HttpClientRequest instance which represents an HTTP OPTIONS request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.

Parameters:

  • uri. (String)
    A relative URI where to perform the OPTIONS on the server.
  • hndlr. (Block)
    The handler to be called with the Vertx::HttpClientResponse


213
214
215
# File 'src/main/api_shim/core/http.rb', line 213

def options(uri, &hndlr)
  HttpClientRequest.new(@j_del.options(uri, resp_handler(hndlr)))
end

- (Object) patch(uri, &hndlr)

This method returns an Vertx::HttpClientRequest instance which represents an HTTP PATCH request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.

Parameters:

  • uri. (String)
    A relative URI where to perform the PATCH on the server.
  • hndlr. (Block)
    The handler to be called with the Vertx::HttpClientResponse


277
278
279
# File 'src/main/api_shim/core/http.rb', line 277

def patch(uri, &hndlr)
  HttpClientRequest.new(@j_del.patch(uri, resp_handler(hndlr)))
end

- (Object) port(val = nil)

Get or set port


151
152
153
154
155
156
157
158
# File 'src/main/api_shim/core/http.rb', line 151

def port(val = nil)
  if val
    @j_del.setPort(val)
    self
  else
    @j_del.getPort
  end
end

- (Object) port=(val)

Set the port that the client will attempt to connect to on the server on. The default value is 80

Parameters:

  • val. (FixNum)
    The port value.


145
146
147
148
# File 'src/main/api_shim/core/http.rb', line 145

def port=(val)
  @j_del.setPort(val)
  self
end

- (Object) post(uri, &hndlr)

This method returns an Vertx::HttpClientRequest instance which represents an HTTP POST request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.

Parameters:

  • uri. (String)
    A relative URI where to perform the POST on the server.
  • hndlr. (Block)
    The handler to be called with the Vertx::HttpClientResponse


237
238
239
# File 'src/main/api_shim/core/http.rb', line 237

def post(uri, &hndlr)
  HttpClientRequest.new(@j_del.post(uri, resp_handler(hndlr)))
end

- (Object) put(uri, &hndlr)

This method returns an Vertx::HttpClientRequest instance which represents an HTTP PUT request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.

Parameters:

  • uri. (String)
    A relative URI where to perform the PUT on the server.
  • hndlr. (Block)
    The handler to be called with the Vertx::HttpClientResponse


245
246
247
# File 'src/main/api_shim/core/http.rb', line 245

def put(uri, &hndlr)
  HttpClientRequest.new(@j_del.put(uri, resp_handler(hndlr)))
end

- (Object) request(method, uri, &hndlr)

This method returns an Vertx::HttpClientRequest instance which represents an HTTP request with the specified method and uri. When an HTTP response is received from the server the handler is called passing in the response.

Parameters:

  • method. (String)
    The HTTP method. Can be one of OPTIONS, HEAD, GET, POST, PUT, DELETE, TRACE, CONNECT.
  • uri. (String)
    A relative URI where to perform the OPTIONS on the server.
  • hndlr. (Block)
    The handler to be called with the Vertx::HttpClientResponse


286
287
288
# File 'src/main/api_shim/core/http.rb', line 286

def request(method, uri, &hndlr)
  HttpClientRequest.new(@j_del.request(method, uri, resp_handler(hndlr)))
end

- (Object) trace(uri, &hndlr)

This method returns an Vertx::HttpClientRequest instance which represents an HTTP TRACE request with the specified uri. When an HTTP response is received from the server the handler is called passing in the response.

Parameters:

  • uri. (String)
    A relative URI where to perform the TRACE on the server.
  • hndlr. (Block)
    The handler to be called with the Vertx::HttpClientResponse


261
262
263
# File 'src/main/api_shim/core/http.rb', line 261

def trace(uri, &hndlr)
  HttpClientRequest.new(@j_del.trace(uri, resp_handler(hndlr)))
end

- (Object) verify_host(val = nil)

Get or set verify host


178
179
180
181
182
183
184
185
# File 'src/main/api_shim/core/http.rb', line 178

def verify_host(val = nil)
  if val
    @j_del.setVerifyHost(val)
    self
  else
    @j_del.isVerifyHost
  end
end