Class: Vertx::HttpClient
- Inherits:
-
Object
- Object
- Vertx::HttpClient
- 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.
Instance Method Summary (collapse)
-
- (Object) close
Close the client.
-
- (Object) connect(uri, &hndlr)
This method returns an HttpClientRequest instance which represents an HTTP CONNECT request with the specified uri.
-
- (Object) connect_web_socket(uri, &hndlr)
Attempt to connect a WebSocket to the specified URI.
-
- (Object) delete(uri, &hndlr)
This method returns an HttpClientRequest instance which represents an HTTP DELETE request with the specified uri.
-
- (Object) exception_handler(&hndlr)
Set the exception handler.
-
- (Object) get(uri, &hndlr)
This method returns an HttpClientRequest instance which represents an HTTP GET request with the specified uri.
-
- (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.
-
- (Object) head(uri, &hndlr)
This method returns an HttpClientRequest instance which represents an HTTP HEAD request with the specified uri.
-
- (Object) host(val = nil)
Get or set host.
-
- (Object) host=(val)
Set the host name or ip address that the client will attempt to connect to on the server on.
-
- (HttpClient) initialize
constructor
Create a new HttpClient.
-
- (Object) keep_alive(val = nil)
Get or set keep alive.
-
- (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.
-
- (Object) max_pool_size(val = nil)
Get or set the max pool size.
-
- (Object) max_pool_size=(val)
Set the maximum pool size.
-
- (Object) options(uri, &hndlr)
This method returns an HttpClientRequest instance which represents an HTTP OPTIONS request with the specified uri.
-
- (Object) patch(uri, &hndlr)
This method returns an HttpClientRequest instance which represents an HTTP PATCH request with the specified uri.
-
- (Object) port(val = nil)
Get or set port.
-
- (Object) port=(val)
Set the port that the client will attempt to connect to on the server on.
-
- (Object) post(uri, &hndlr)
This method returns an HttpClientRequest instance which represents an HTTP POST request with the specified uri.
-
- (Object) put(uri, &hndlr)
This method returns an HttpClientRequest instance which represents an HTTP PUT request with the specified uri.
-
- (Object) request(method, uri, &hndlr)
This method returns an HttpClientRequest instance which represents an HTTP request with the specified method and uri.
-
- (Object) trace(uri, &hndlr)
This method returns an HttpClientRequest instance which represents an HTTP TRACE request with the specified uri.
-
- (Object) verify_host(val = nil)
Get or set verify host.
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
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.
213 214 215 |
# File 'src/main/api_shim/core/http.rb', line 213 def (uri, &hndlr) HttpClientRequest.new(@j_del.(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.
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
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.
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.
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.
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.
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 |