Class: Pinot::HttpClient
- Inherits:
-
Object
- Object
- Pinot::HttpClient
- Defined in:
- lib/pinot/transport.rb
Defined Under Namespace
Classes: PoolEntry
Constant Summary collapse
- DEFAULT_POOL_SIZE =
5- DEFAULT_KEEP_ALIVE_TIMEOUT =
30
Instance Method Summary collapse
- #close ⇒ Object
- #delete(url, headers: {}) ⇒ Object
- #get(url, headers: {}) ⇒ Object
-
#initialize(timeout: nil, tls_config: nil, pool_size: nil, keep_alive_timeout: nil) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #post(url, body:, headers: {}) ⇒ Object
Constructor Details
#initialize(timeout: nil, tls_config: nil, pool_size: nil, keep_alive_timeout: nil) ⇒ HttpClient
Returns a new instance of HttpClient.
14 15 16 17 18 19 20 21 22 |
# File 'lib/pinot/transport.rb', line 14 def initialize(timeout: nil, tls_config: nil, pool_size: nil, keep_alive_timeout: nil) @timeout = timeout @tls_config = tls_config @max_pool_size = pool_size || DEFAULT_POOL_SIZE @keep_alive_timeout = keep_alive_timeout || DEFAULT_KEEP_ALIVE_TIMEOUT @pool = {} @pool_mutex = Mutex.new @reaper = start_reaper end |
Instance Method Details
#close ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/pinot/transport.rb', line 52 def close @reaper.kill rescue nil @pool_mutex.synchronize do @pool.each_value do |entries| entries.each { |entry| entry.http.finish rescue nil } end @pool.clear end end |
#delete(url, headers: {}) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/pinot/transport.rb', line 43 def delete(url, headers: {}) uri = URI.parse(url) with_connection(url) do |http| req = Net::HTTP::Delete.new(uri.request_uri) headers.each { |k, v| req[k] = v } http.request(req) end end |
#get(url, headers: {}) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/pinot/transport.rb', line 34 def get(url, headers: {}) uri = URI.parse(url) with_connection(url) do |http| req = Net::HTTP::Get.new(uri.request_uri) headers.each { |k, v| req[k] = v } http.request(req) end end |
#post(url, body:, headers: {}) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/pinot/transport.rb', line 24 def post(url, body:, headers: {}) uri = URI.parse(url) with_connection(url) do |http| req = Net::HTTP::Post.new(uri.request_uri) headers.each { |k, v| req[k] = v } req.body = body http.request(req) end end |