Class: UU::OS::HTTP::HTTPClient
- Inherits:
-
Object
- Object
- UU::OS::HTTP::HTTPClient
- Defined in:
- uu_os_connection-2.2.4/lib/uu/os/http/http_client.rb
Overview
HTTPClient is used for execution of common HTTP requests.
Constant Summary
Instance Method Summary (collapse)
-
- (Fixnum, Float) connect_timeout
Returns timeout for connection initialization.
-
- (void) connect_timeout=(timeout)
Sets timeout for connection initialization.
-
- (HTTPClient) initialize(base_url, *path)
constructor
Creates new instance of HTTPClient for given base URL and optional path.
-
- (void) keepalive_timeout=(timeout)
Sets connection keepalive timeout (timeout within which are connections to same server reused).
-
- (UU::OS::HTTP::HTTPGet) prepare_get(*path)
Prepares GET request for given optional path.
-
- (UU::OS::HTTP::HTTPPost) prepare_post(*path)
Prepares POST request for given optional path.
-
- (Fixnum, Float) request_timeout
Returns timeout in which request must be processed (sum of sending of request and receiving response).
-
- (void) request_timeout=(timeout)
Sets timeout in which request must be processed (sum of sending of request and receiving response).
-
- (void) set_header(name, *value)
Sets HTTP header to be used for each invoked request using this instance of HTTPClient.
-
- (void) ssl_cert_store=(cert_store)
Sets custom SSL certificate store to be able to modify default trusted CAs.
-
- (TrueClass, FalseClass) ssl_validation
Returns configuration of SSL validation.
-
- (void) ssl_validation=(enabled)
Enable or disable SSL validation.
-
- (String, Symbol) ssl_version
Returns SSL version to be used for communication.
-
- (void) ssl_version=(version)
Sets SSL version to be used for communication.
-
- (TrueClass, FalseClass) tranparent_gzip_decompression
Returns configuration of transparent GZip decompression.
-
- (void) tranparent_gzip_decompression=(enabled)
Enable or disable transparent GZip decompression.
Constructor Details
- (HTTPClient) initialize(base_url, *path)
Creates new instance of HTTPClient for given base URL and optional path.
140 141 142 143 144 |
# File 'uu_os_connection-2.2.4/lib/uu/os/http/http_client.rb', line 140 def initialize(base_url, *path) @base_url = base_url @path = concat_path(*path) @client = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(method, *args, &block) (private)
Allow to invoke other HTTP methods than POST and GET (needed e.g. for UDS which uses DELETE, but might be necessary for integration with thirdparty services).
442 443 444 445 446 447 448 449 450 |
# File 'uu_os_connection-2.2.4/lib/uu/os/http/http_client.rb', line 442 def method_missing(method, *args, &block) #:nodoc: method_name = method.to_s if method_name =~ /^prepare_/ method_type = method_name[8..-1].to_sym UU::OS::HTTP::HTTPMethod.new(self, concat_path(*args), method_type) else super end end |
Instance Method Details
- (Fixnum, Float) connect_timeout
Returns timeout for connection initialization.
148 149 150 |
# File 'uu_os_connection-2.2.4/lib/uu/os/http/http_client.rb', line 148 def connect_timeout client.connect_timeout end |
- (void) connect_timeout=(timeout)
This method returns an undefined value.
Sets timeout for connection initialization.
155 156 157 158 159 160 161 162 |
# File 'uu_os_connection-2.2.4/lib/uu/os/http/http_client.rb', line 155 def connect_timeout=(timeout) return if timeout.nil? # Do not create new instance if default value is not changed if client.connect_timeout != timeout @client = self.class.send(:__new_client__) if @client.nil? @client.connect_timeout = timeout end end |
- (void) keepalive_timeout=(timeout)
This method returns an undefined value.
Sets connection keepalive timeout (timeout within which are connections to same server reused). Defaults to 15 seconds.
332 333 334 335 336 337 338 339 |
# File 'uu_os_connection-2.2.4/lib/uu/os/http/http_client.rb', line 332 def keepalive_timeout=(timeout) return if timeout.nil? # Do not create new instance if default value is not changed if client.keep_alive_timeout != timeout.to_i @client = self.class.send(:__new_client__) if @client.nil? @client.keep_alive_timeout = timeout.to_i end end |
- (UU::OS::HTTP::HTTPGet) prepare_get(*path)
Prepares GET request for given optional path. In case path is not given
request will be sent to URL defined by base_url
and
path
given for HTTPClient initialization.
367 368 369 |
# File 'uu_os_connection-2.2.4/lib/uu/os/http/http_client.rb', line 367 def prepare_get(*path) UU::OS::HTTP::HTTPGet.new(self, concat_path(*path)) end |
- (UU::OS::HTTP::HTTPPost) prepare_post(*path)
Prepares POST request for given optional path. In case path is not given
request will be sent to URL defined by base_url
and
path
given for HTTPClient initialization.
376 377 378 |
# File 'uu_os_connection-2.2.4/lib/uu/os/http/http_client.rb', line 376 def prepare_post(*path) UU::OS::HTTP::HTTPPost.new(self, concat_path(*path)) end |
- (Fixnum, Float) request_timeout
Returns timeout in which request must be processed (sum of sending of request and receiving response).
167 168 169 |
# File 'uu_os_connection-2.2.4/lib/uu/os/http/http_client.rb', line 167 def request_timeout client.receive_timeout end |
- (void) request_timeout=(timeout)
This method returns an undefined value.
Sets timeout in which request must be processed (sum of sending of request and receiving response).
175 176 177 178 179 180 181 182 183 |
# File 'uu_os_connection-2.2.4/lib/uu/os/http/http_client.rb', line 175 def request_timeout=(timeout) return if timeout.nil? # Do not create new instance if default value is not changed if client.receive_timeout != timeout @client = self.class.send(:__new_client__) if @client.nil? @client.receive_timeout = timeout @client.send_timeout = timeout end end |
- (void) set_header(name, *value)
This method returns an undefined value.
Sets HTTP header to be used for each invoked request using this instance of HTTPClient.
357 358 359 360 |
# File 'uu_os_connection-2.2.4/lib/uu/os/http/http_client.rb', line 357 def set_header(name, *value) @headers = UU::OS::HTTP::HTTPHeaders.new(DEFAULT_HEADERS) if @headers.nil? @headers[name] = value end |
- (void) ssl_cert_store=(cert_store)
This method returns an undefined value.
Sets custom SSL certificate store to be able to modify default trusted CAs.
296 297 298 299 300 301 302 303 304 305 306 |
# File 'uu_os_connection-2.2.4/lib/uu/os/http/http_client.rb', line 296 def ssl_cert_store=(cert_store) return if cert_store.nil? @client = self.class.send(:__new_client__) if @client.nil? store = OpenSSL::X509::Store.new if File.directory?(cert_store) store.add_path(cert_store) else store.add_file(cert_store) end client.ssl_config.cert_store = store end |
- (TrueClass, FalseClass) ssl_validation
Returns configuration of SSL validation.
218 219 220 |
# File 'uu_os_connection-2.2.4/lib/uu/os/http/http_client.rb', line 218 def ssl_validation return client.ssl_config.verify_mode == SSL_VALIDATION_ENABLED end |
- (void) ssl_validation=(enabled)
This method returns an undefined value.
Enable or disable SSL validation. If enabled, server certificate is checked and exception is thrown in case it is not valid or is untrusted.
226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'uu_os_connection-2.2.4/lib/uu/os/http/http_client.rb', line 226 def ssl_validation=(enabled) return if enabled.nil? # Do not create new instance if default value is not changed if (client.ssl_config.verify_mode == SSL_VALIDATION_ENABLED) != enabled @client = self.class.send(:__new_client__) if @client.nil? if enabled client.ssl_config.verify_mode = SSL_VALIDATION_ENABLED else client.ssl_config.verify_mode = SSL_VALIDATION_DISABLED end end end |
- (String, Symbol) ssl_version
Returns SSL version to be used for communication. Value :auto or
nil
means suitable version is automatically chosen based on
negotiation with server.
261 262 263 |
# File 'uu_os_connection-2.2.4/lib/uu/os/http/http_client.rb', line 261 def ssl_version return client.ssl_config.ssl_version end |
- (void) ssl_version=(version)
This method returns an undefined value.
Sets SSL version to be used for communication.
269 270 271 272 273 274 275 |
# File 'uu_os_connection-2.2.4/lib/uu/os/http/http_client.rb', line 269 def ssl_version=(version) # Do not create new instance if default value is not changed if (((client.ssl_config.ssl_version.nil?) || (client.ssl_config.ssl_version == :auto)) && !((version.nil?) || (version == :auto))) @client = self.class.send(:__new_client__) if @client.nil? @client.ssl_config.ssl_version = (version.nil? ? :auto : version) end end |
- (TrueClass, FalseClass) tranparent_gzip_decompression
Returns configuration of transparent GZip decompression.
187 188 189 |
# File 'uu_os_connection-2.2.4/lib/uu/os/http/http_client.rb', line 187 def tranparent_gzip_decompression client.transparent_gzip_decompression end |
- (void) tranparent_gzip_decompression=(enabled)
This method returns an undefined value.
Enable or disable transparent GZip decompression. If enabled corresponding Accept header is automatically send with request.
195 196 197 198 199 200 201 202 |
# File 'uu_os_connection-2.2.4/lib/uu/os/http/http_client.rb', line 195 def tranparent_gzip_decompression=(enabled) return if enabled.nil? # Do not create new instance if default value is not changed if client.gransparent_gzip_decompression != enabled @client = self.class.send(:__new_client__) if @client.nil? @client.transparent_gzip_decompression = enabled end end |