Class: NetHttp2::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/net-http2/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, options = {}) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
18
19
20
21
22
# File 'lib/net-http2/client.rb', line 13

def initialize(url, options={})
  @uri         = URI.parse(url)
  @ssl_context = add_npn_to_context(options[:ssl_context] || OpenSSL::SSL::SSLContext.new)

  @is_ssl = (@uri.scheme == 'https')

  @pipe_r, @pipe_w = Socket.pair(:UNIX, :STREAM, 0)
  @socket_thread   = nil
  @mutex           = Mutex.new
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



11
12
13
# File 'lib/net-http2/client.rb', line 11

def uri
  @uri
end

Instance Method Details

#async_delete(path, headers = {}, options = {}, &block) ⇒ Object



59
60
61
62
# File 'lib/net-http2/client.rb', line 59

def async_delete(path, headers={}, options={}, &block)
  request = NetHttp2::Request::Delete.new(@uri, path, headers, options)
  async_call_with request, &block
end

#async_get(path, headers = {}, options = {}, &block) ⇒ Object



44
45
46
47
# File 'lib/net-http2/client.rb', line 44

def async_get(path, headers={}, options={}, &block)
  request = NetHttp2::Request::Get.new(@uri, path, headers, options)
  async_call_with request, &block
end

#async_post(path, body, headers = {}, options = {}, &block) ⇒ Object



49
50
51
52
# File 'lib/net-http2/client.rb', line 49

def async_post(path, body, headers={}, options={}, &block)
  request = NetHttp2::Request::Post.new(@uri, path, body, headers, options)
  async_call_with request, &block
end

#async_put(path, body, headers = {}, options = {}, &block) ⇒ Object



54
55
56
57
# File 'lib/net-http2/client.rb', line 54

def async_put(path, body, headers={}, options={}, &block)
  request = NetHttp2::Request::Put.new(@uri, path, body, headers, options)
  async_call_with request, &block
end

#closeObject



68
69
70
71
72
73
74
75
# File 'lib/net-http2/client.rb', line 68

def close
  exit_thread(@socket_thread)

  @h2            = nil
  @pipe_r        = nil
  @pipe_w        = nil
  @socket_thread = nil
end

#delete(path, headers = {}, options = {}) ⇒ Object



39
40
41
42
# File 'lib/net-http2/client.rb', line 39

def delete(path, headers={}, options={})
  request = NetHttp2::Request::Delete.new(@uri, path, headers, options)
  call_with request
end

#get(path, headers = {}, options = {}) ⇒ Object



24
25
26
27
# File 'lib/net-http2/client.rb', line 24

def get(path, headers={}, options={})
  request = NetHttp2::Request::Get.new(@uri, path, headers, options)
  call_with request
end

#post(path, body, headers = {}, options = {}) ⇒ Object



29
30
31
32
# File 'lib/net-http2/client.rb', line 29

def post(path, body, headers={}, options={})
  request = NetHttp2::Request::Post.new(@uri, path, body, headers, options)
  call_with request
end

#put(path, body, headers = {}, options = {}) ⇒ Object



34
35
36
37
# File 'lib/net-http2/client.rb', line 34

def put(path, body, headers={}, options={})
  request = NetHttp2::Request::Put.new(@uri, path, body, headers, options)
  call_with request
end

#ssl?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/net-http2/client.rb', line 64

def ssl?
  @is_ssl
end