Core Manticore client, with a backingPoolingHttpClientConnectionManager
Modules:ProxiesInterface,TrustStrategiesClasses:AsyncProxy,BackgroundProxy,BaseProxy,CombinedTrustStrategy,CustomTrustStrategy,StubProxy
The default maximum pool size for requests
50
60
10
10
5
false
false
Returns the value of attribute client.
Remove all pending asynchronous requests.
Wipe all currently-set stubs.
Release resources held by this client, namely: - close the internal http client - shutdown the connection pool - stops accepting async requests in the executor.
Perform a HTTP DELETE request.
Execute all queued async requests.
Get at the underlying ExecutorService used to invoke asynchronous calls.
Perform a HTTP GET request.
Perform a HTTP HEAD request.
Perform an HTTP request, passing the method as a parameter.
Create a new HTTP client with a backing request pool.
Perform a HTTP OPTIONS request.
Perform a HTTP PATCH request.
Return a hash of statistics about this client’s HTTP connection pool.
Perform a HTTP POST request.
Perform a HTTP PUT request.
Cause this client to return a stubbed response for this URL.
Cause this client to unstubbed previously-stubbed URL.
#async,#background,#respond_with
Create a new HTTP client with a backing request pool. if you pass a block to the initializer, the underlyingHttpClientBuilder andRequestConfig.Builder will be yielded so that you can operate on them directly.
Simple instantiation and usage
client=Manticore::Client.newclient.get("http://www.google.com")
Instantiation with a block
client=Manticore::Client.new(socket_timeout:5)do|http_client_builder,request_builder|http_client_builder.disable_redirect_handlingend
Parameters:
Client pool options
Options Hash (options):
The user agent used in requests.
The maximum number of active connections in the pool
Sets the maximum number of active connections for a given target endpoint
enable or disable automatic cookie management between requests
enable or disable transparent gzip/deflate support
Sets the timeout for requests. RaisesTimeout on failure.
Sets the timeout for connections. Raises Manticore::Timeout on failure.
Sets SO_TIMEOUT for open connections. A value of 0 is an infinite timeout. Raises Manticore::Timeout on failure.
Enable or disable Nagle’s algorithm
Sets the maximum number of redirects to follow.
Sets the number of times the client will automatically retry failed requests.
If true, Manticore will automatically retry failed requests with non-idempotent verbs. Otherwise, it only automatically retries on GET, HEAD, PUT, DELETE, OPTIONS, and TRACE
Enable support for HTTP 100
Enable support for stale connection checking. Adds overhead.
Connections that haven’t been used in this many milliseconds will be validated before being used. Set to a negative number to disable.
Proxy host in form:proxy.org:1234
Proxy host in form: ‘proxy.org’[, port: 80[, scheme: ‘http’[, user: ‘username@host’, password: ‘password’]]]
Proxy host in form: ‘proxy.org:1234’[, user: ‘username@host’, password: ‘password’]]]
Proxy host as a URI object
Whether to allow connections to be reused. Defaults to true.
Hash of options for configuring SSL
A list of protocols that Manticore should accept
A list of cipher suites that Manticore should accept
Hostname verification setting. Set to ‘:none` to turn off hostname verification. Setting to `:browser` will cause Manticore to accept a certificate for *.foo.com for all subdomains and sub-subdomains (eg a.b.foo.com). The default `:default` is like `:browser` but more strict - only accepts a single level of subdomains for wildcards, eg `b.foo.com` will be accepted for a `*.foo.com` certificate, but `a.b.foo.com` will not be.
A trust strategy to use in addition to any built by ‘ssl`. @see Client::TrustStrategiesInterface#coerce
Path to a custom trust store to use the verifying SSL connections
Password used for decrypting the server trust store
Format of the trust store, ie “JKS” or “PKCS12”. If left nil, the type will be inferred from the truststore filename.
Path to a custom key store to use for client certificate authentication
Password used for decrypting the client auth key store
Format of the key store, ie “JKS” or “PKCS12”. If left nil, the type will be inferred from the keystore filename.
OpenSSL-style path to an X.509 certificate to use to validate SSL certificates
A string containing a base64-encoded X.509 certificate, OR a path to an OpenSSL-style X.509 certificate, OR an instance of OpenSSL::X509::Certificate
A string containing a base64-encoded RSA key to use for client authentication, OR a path to an OpenSSL-style RSA key, OR an instance of OpenSSL::PKey::PKey
Turn on or off connection state tracking. This helps prevent SSL information from leaking across threads, but means that connections can’t be shared across those threads. This should generally be left off unless you know what you’re doing.
Yields:
See Also:
198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 | # File 'lib/manticore/client.rb', line 198definitialize(={})@finalizer=Finalizer.newself.class.shutdown_on_finalizeself,@finalizerbuilder=client_builderbuilder.set_user_agent.fetch(:user_agent,"Manticore#{VERSION}")@options=@use_cookies=.fetch(:cookies,false)builder.unless@use_cookiesbuilder.disable_content_compressionif.fetch(:compression,true)==falsebuilder.set_proxyget_proxy_host([:proxy])if.key?(:proxy)builder.set_retry_handlerLoggingStandardRetryHandler.new.fetch(:automatic_retries,3),.fetch(:retry_non_idempotent,false)# http://hc.apache.org/httpcomponents-client-ga/tutorial/html/advanced.html#stateful_conn# By default this is used to prevent different contexts from accessing SSL data# Since we're running this for JRuby which does not have context separation within the JVM# We can disable this for connection reuse.builder.disable_connection_stateunless.fetch(:ssl,{}).fetch(:track_state,false)@keepalive=.fetch(:keepalive,true)if@keepalive==falsebuilder.set_connection_reuse_strategyNoConnectionReuseStrategy::INSTANCE# return falseelsebuilder.set_connection_reuse_strategyDefaultConnectionReuseStrategy.newendbuilder.set_default_socket_config()builder.set_connection_managerpool()request_config=RequestConfig.customrequest_config.set_connection_request_timeout.fetch(:request_timeout,DEFAULT_REQUEST_TIMEOUT)*1000request_config.set_connect_timeout.fetch(:connect_timeout,DEFAULT_CONNECT_TIMEOUT)*1000request_config.set_socket_timeout.fetch(:socket_timeout,DEFAULT_SOCKET_TIMEOUT)*1000request_config.set_max_redirects.fetch(:max_redirects,DEFAULT_MAX_REDIRECTS)request_config.set_expect_continue_enabled.fetch(:expect_continue,DEFAULT_EXPECT_CONTINUE)request_config.set_stale_connection_check_enabled.fetch(:stale_check,DEFAULT_STALE_CHECK)request_config.set_circular_redirects_allowedfalseyieldbuilder,request_configifblock_given?builder.set_default_request_configrequest_config.build@client=builder.buildfinalize@client,:close@options=@async_requests=Queue.new@stubs={}end |
Returns the value of attribute client.
138139140 | # File 'lib/manticore/client.rb', line 138defclient@clientend |
418419420 | # File 'lib/manticore/client.rb', line 418defself.shutdown_on_finalize(client,finalizer)ObjectSpace.define_finalizer(client,finalizer)end |
Remove all pending asynchronous requests.
Returns:
nil
346347348349 | # File 'lib/manticore/client.rb', line 346defclear_pending@async_requests.clearnilend |
Wipe all currently-set stubs.
339340341 | # File 'lib/manticore/client.rb', line 339defclear_stubs!@stubs.clearend |
In versions before 0.9 this method only closed the underlying ‘CloseableHttpClient`
Release resources held by this client, namely:
- close the internal http client- shutdown the connection pool- stops accepting async requests in the executor
After this call the client is no longer usable.
375376377378379380381382383384385386387388389390391392 | # File 'lib/manticore/client.rb', line 375defclose(await:nil)ObjectSpace.undefine_finalizer(self)@finalizer.call# which does ~ :# @executor&.shutdown rescue nil# @client&.close# @pool&.shutdown rescue nilcaseawaitwhenfalse,nil@executor&.shutdown_nowrescuenilwhenNumeric# NOTE: the concept of awaiting gracefully might/should also be used with the pool/client closingmillis=java.util.concurrent.TimeUnit::MILLISECONDS@executor&.await_termination(await*1000,millis)rescuenilelsenilend@async_requests.closeend |
Perform a HTTP DELETE request
Simple usage
body=client.delete("http://example.com/some/resource",params:{foo:"bar"},headers:{"X-Custom-Header"=>"whee"}).body
Passing a block as the success handler:
body=client.delete("http://example.com/some/resource",params:{foo:"bar"},headers:{"X-Custom-Header"=>"whee"}){|response|response.body}
Explicit success handler:
body=client.delete("http://example.com/some/resource",params:{foo:"bar"},headers:{"X-Custom-Header"=>"whee"}).on_success{|response|response.body}
Parameters:
URL to request
Options Hash (options):
Hash of options to be added to the URL as part of the query string
Hash of options to pass as a request body. For GET, HEAD, and DELETE requests, :params will be treated as :query if :query is not present.
Hash of options to pass as additional request headers
Proxy host in form:proxy.org:1234
Proxy host in form: ‘proxy.org’[, port: 80[, scheme: ‘http’]]
Proxy host as a URI object
Request-specific connect timeout (in seconds)
Request-specific socket timeout (in seconds)
Request-specific request timeout (in seconds)
Request-specific maximum redirect limit
Specify whether this request should follow redirects
Specify authentication for the request
Username to auth with
Password to auth with
Eagerly offer the Authorization header before the server challenges for it. You should not use this unless you know you specifically need it, as misuse of it can leak user credentials.
Returns:
Raises:
on socket, connection, or response timeout
on internal socket exception (ie, unexpected socket closure)
on protocol errors such as an SSL handshake failure or connection exception
on DNS resolution failure
289290291292293 | # File 'lib/manticore/client.rb', line 289defdelete(url,={},&block)=treat_params_as_query()delete_class=[:body]?HttpDeleteWithEntity:HttpDeleterequestdelete_class,url,,&blockend |
Execute all queued async requests
Returns:
An array of the responses from the requests executed.
354355356357358359360361362363364365366 | # File 'lib/manticore/client.rb', line 354defexecute!method=executor.java_method(:submit,[java.util.concurrent.Callable.java_class])result=[]result<<method.call(@async_requests.pop)until@async_requests.empty?result.mapdo|future|beginfuture.getrescueJava::JavaUtilConcurrent::ExecutionException=>e# These exceptions should be handled in on_failure blocks.endendend |
Get at the underlying ExecutorService used to invoke asynchronous calls.
413414415 | # File 'lib/manticore/client.rb', line 413defexecutor@executor||=create_executorend |
Perform a HTTP GET request
Simple usage
body=client.get("http://example.com/some/resource",params:{foo:"bar"},headers:{"X-Custom-Header"=>"whee"}).body
Passing a block as the success handler:
body=client.get("http://example.com/some/resource",params:{foo:"bar"},headers:{"X-Custom-Header"=>"whee"}){|response|response.body}
Explicit success handler:
body=client.get("http://example.com/some/resource",params:{foo:"bar"},headers:{"X-Custom-Header"=>"whee"}).on_success{|response|response.body}
Parameters:
URL to request
Options Hash (options):
Hash of options to be added to the URL as part of the query string
Hash of options to pass as a request body. For GET, HEAD, and DELETE requests, :params will be treated as :query if :query is not present.
Hash of options to pass as additional request headers
Proxy host in form:proxy.org:1234
Proxy host in form: ‘proxy.org’[, port: 80[, scheme: ‘http’]]
Proxy host as a URI object
Request-specific connect timeout (in seconds)
Request-specific socket timeout (in seconds)
Request-specific request timeout (in seconds)
Request-specific maximum redirect limit
Specify whether this request should follow redirects
Specify authentication for the request
Username to auth with
Password to auth with
Eagerly offer the Authorization header before the server challenges for it. You should not use this unless you know you specifically need it, as misuse of it can leak user credentials.
Returns:
Raises:
on socket, connection, or response timeout
on internal socket exception (ie, unexpected socket closure)
on protocol errors such as an SSL handshake failure or connection exception
on DNS resolution failure
262263264265266 | # File 'lib/manticore/client.rb', line 262defget(url,={},&block)=treat_params_as_query()get_class=[:body]?HttpGetWithEntity:HttpGetrequestget_class,url,,&blockend |
Perform a HTTP HEAD request
Simple usage
body=client.head("http://example.com/some/resource",params:{foo:"bar"},headers:{"X-Custom-Header"=>"whee"}).body
Passing a block as the success handler:
body=client.head("http://example.com/some/resource",params:{foo:"bar"},headers:{"X-Custom-Header"=>"whee"}){|response|response.body}
Explicit success handler:
body=client.head("http://example.com/some/resource",params:{foo:"bar"},headers:{"X-Custom-Header"=>"whee"}).on_success{|response|response.body}
Parameters:
URL to request
Options Hash (options):
Hash of options to be added to the URL as part of the query string
Hash of options to pass as a request body. For GET, HEAD, and DELETE requests, :params will be treated as :query if :query is not present.
Hash of options to pass as additional request headers
Proxy host in form:proxy.org:1234
Proxy host in form: ‘proxy.org’[, port: 80[, scheme: ‘http’]]
Proxy host as a URI object
Request-specific connect timeout (in seconds)
Request-specific socket timeout (in seconds)
Request-specific request timeout (in seconds)
Request-specific maximum redirect limit
Specify whether this request should follow redirects
Specify authentication for the request
Username to auth with
Password to auth with
Eagerly offer the Authorization header before the server challenges for it. You should not use this unless you know you specifically need it, as misuse of it can leak user credentials.
Returns:
Raises:
on socket, connection, or response timeout
on internal socket exception (ie, unexpected socket closure)
on protocol errors such as an SSL handshake failure or connection exception
on DNS resolution failure
276277278279 | # File 'lib/manticore/client.rb', line 276defhead(url,={},&block)=treat_params_as_query()requestHttpHead,url,,&blockend |
Perform an HTTP request, passing the method as a parameter
Parameters:
Method to call (get put head post options patch)
URL to request
Options Hash (options):
Hash of options to be added to the URL as part of the query string
Hash of options to pass as a request body. For GET, HEAD, and DELETE requests, :params will be treated as :query if :query is not present.
Hash of options to pass as additional request headers
Proxy host in form:proxy.org:1234
Proxy host in form: ‘proxy.org’[, port: 80[, scheme: ‘http’]]
Proxy host as a URI object
Request-specific connect timeout (in seconds)
Request-specific socket timeout (in seconds)
Request-specific request timeout (in seconds)
Request-specific maximum redirect limit
Specify whether this request should follow redirects
Specify authentication for the request
Username to auth with
Password to auth with
Eagerly offer the Authorization header before the server challenges for it. You should not use this unless you know you specifically need it, as misuse of it can leak user credentials.
Returns:
Raises:
on socket, connection, or response timeout
on internal socket exception (ie, unexpected socket closure)
on protocol errors such as an SSL handshake failure or connection exception
on DNS resolution failure
317318319320321322323324 | # File 'lib/manticore/client.rb', line 317defhttp(method,url,={},&block)casemethod.to_s.downcasewhen*%w(getputheadpostdeleteoptionspatch)sendmethod,url,,&blockelseraise"Invalid method:#{method}"endend |
Perform a HTTP OPTIONS request
Simple usage
body=client.("http://example.com/some/resource",params:{foo:"bar"},headers:{"X-Custom-Header"=>"whee"}).body
Passing a block as the success handler:
body=client.("http://example.com/some/resource",params:{foo:"bar"},headers:{"X-Custom-Header"=>"whee"}){|response|response.body}
Explicit success handler:
body=client.("http://example.com/some/resource",params:{foo:"bar"},headers:{"X-Custom-Header"=>"whee"}).on_success{|response|response.body}
Parameters:
URL to request
Options Hash (options):
Hash of options to be added to the URL as part of the query string
Hash of options to pass as a request body. For GET, HEAD, and DELETE requests, :params will be treated as :query if :query is not present.
Hash of options to pass as additional request headers
Proxy host in form:proxy.org:1234
Proxy host in form: ‘proxy.org’[, port: 80[, scheme: ‘http’]]
Proxy host as a URI object
Request-specific connect timeout (in seconds)
Request-specific socket timeout (in seconds)
Request-specific request timeout (in seconds)
Request-specific maximum redirect limit
Specify whether this request should follow redirects
Specify authentication for the request
Username to auth with
Password to auth with
Eagerly offer the Authorization header before the server challenges for it. You should not use this unless you know you specifically need it, as misuse of it can leak user credentials.
Returns:
Raises:
on socket, connection, or response timeout
on internal socket exception (ie, unexpected socket closure)
on protocol errors such as an SSL handshake failure or connection exception
on DNS resolution failure
297298299 | # File 'lib/manticore/client.rb', line 297def(url,={},&block)requestHttpOptions,url,,&blockend |
Perform a HTTP PATCH request
Simple usage
body=client.patch("http://example.com/some/resource",params:{foo:"bar"},headers:{"X-Custom-Header"=>"whee"}).body
Passing a block as the success handler:
body=client.patch("http://example.com/some/resource",params:{foo:"bar"},headers:{"X-Custom-Header"=>"whee"}){|response|response.body}
Explicit success handler:
body=client.patch("http://example.com/some/resource",params:{foo:"bar"},headers:{"X-Custom-Header"=>"whee"}).on_success{|response|response.body}
Parameters:
URL to request
Options Hash (options):
Hash of options to be added to the URL as part of the query string
Hash of options to pass as a request body. For GET, HEAD, and DELETE requests, :params will be treated as :query if :query is not present.
Hash of options to pass as additional request headers
Proxy host in form:proxy.org:1234
Proxy host in form: ‘proxy.org’[, port: 80[, scheme: ‘http’]]
Proxy host as a URI object
Request-specific connect timeout (in seconds)
Request-specific socket timeout (in seconds)
Request-specific request timeout (in seconds)
Request-specific maximum redirect limit
Specify whether this request should follow redirects
Specify authentication for the request
Username to auth with
Password to auth with
Eagerly offer the Authorization header before the server challenges for it. You should not use this unless you know you specifically need it, as misuse of it can leak user credentials.
Body to pass with the request
Returns:
Raises:
on socket, connection, or response timeout
on internal socket exception (ie, unexpected socket closure)
on protocol errors such as an SSL handshake failure or connection exception
on DNS resolution failure
303304305 | # File 'lib/manticore/client.rb', line 303defpatch(url,={},&block)requestHttpPatch,url,,&blockend |
Return a hash of statistics about this client’s HTTP connection pool
248249250251252253254255256 | # File 'lib/manticore/client.rb', line 248defpool_statsstats=@pool.get_total_stats{max:stats.get_max,leased:stats.get_leased,pending:stats.get_pending,available:stats.get_available,}end |
Perform a HTTP POST request
Simple usage
body=client.post("http://example.com/some/resource",params:{foo:"bar"},headers:{"X-Custom-Header"=>"whee"}).body
Passing a block as the success handler:
body=client.post("http://example.com/some/resource",params:{foo:"bar"},headers:{"X-Custom-Header"=>"whee"}){|response|response.body}
Explicit success handler:
body=client.post("http://example.com/some/resource",params:{foo:"bar"},headers:{"X-Custom-Header"=>"whee"}).on_success{|response|response.body}
Parameters:
URL to request
Options Hash (options):
Hash of options to be added to the URL as part of the query string
Hash of options to pass as a request body. For GET, HEAD, and DELETE requests, :params will be treated as :query if :query is not present.
Hash of options to pass as additional request headers
Proxy host in form:proxy.org:1234
Proxy host in form: ‘proxy.org’[, port: 80[, scheme: ‘http’]]
Proxy host as a URI object
Request-specific connect timeout (in seconds)
Request-specific socket timeout (in seconds)
Request-specific request timeout (in seconds)
Request-specific maximum redirect limit
Specify whether this request should follow redirects
Specify authentication for the request
Username to auth with
Password to auth with
Eagerly offer the Authorization header before the server challenges for it. You should not use this unless you know you specifically need it, as misuse of it can leak user credentials.
Body to pass with the request
Returns:
Raises:
on socket, connection, or response timeout
on internal socket exception (ie, unexpected socket closure)
on protocol errors such as an SSL handshake failure or connection exception
on DNS resolution failure
283284285 | # File 'lib/manticore/client.rb', line 283defpost(url,={},&block)requestHttpPost,url,,&blockend |
Perform a HTTP PUT request
Simple usage
body=client.put("http://example.com/some/resource",params:{foo:"bar"},headers:{"X-Custom-Header"=>"whee"}).body
Passing a block as the success handler:
body=client.put("http://example.com/some/resource",params:{foo:"bar"},headers:{"X-Custom-Header"=>"whee"}){|response|response.body}
Explicit success handler:
body=client.put("http://example.com/some/resource",params:{foo:"bar"},headers:{"X-Custom-Header"=>"whee"}).on_success{|response|response.body}
Parameters:
URL to request
Options Hash (options):
Hash of options to be added to the URL as part of the query string
Hash of options to pass as a request body. For GET, HEAD, and DELETE requests, :params will be treated as :query if :query is not present.
Hash of options to pass as additional request headers
Proxy host in form:proxy.org:1234
Proxy host in form: ‘proxy.org’[, port: 80[, scheme: ‘http’]]
Proxy host as a URI object
Request-specific connect timeout (in seconds)
Request-specific socket timeout (in seconds)
Request-specific request timeout (in seconds)
Request-specific maximum redirect limit
Specify whether this request should follow redirects
Specify authentication for the request
Username to auth with
Password to auth with
Eagerly offer the Authorization header before the server challenges for it. You should not use this unless you know you specifically need it, as misuse of it can leak user credentials.
Body to pass with the request
Returns:
Raises:
on socket, connection, or response timeout
on internal socket exception (ie, unexpected socket closure)
on protocol errors such as an SSL handshake failure or connection exception
on DNS resolution failure
270271272 | # File 'lib/manticore/client.rb', line 270defput(url,={},&block)requestHttpPut,url,,&blockend |
Cause this client to return a stubbed response for this URL
Parameters:
URL to stub for
Hash of options to return for the stubbed response
329330331 | # File 'lib/manticore/client.rb', line 329defstub(url,stubs)@stubs[url_as_regex(url)]=stubsend |
Cause this client to unstubbed previously-stubbed URL
334335336 | # File 'lib/manticore/client.rb', line 334defunstub(url)@stubs.delete(url_as_regex(url))end |