Class: Atatus::Transport::Connection::Http Private

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/atatus/transport/connection/http.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary

Constants included from Logging

Logging::LEVELS, Logging::PREFIX

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

#debug, #error, #fatal, #info, #warn

Constructor Details

#initialize(config, headers: nil) ⇒ Http

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Http.



29
30
31
32
33
34
# File 'lib/atatus/transport/connection/http.rb', line 29

def initialize(config, headers: nil)
  @config = config
  @headers = headers || Headers.new(config)
  @client = build_client
  @closed = Concurrent::AtomicBoolean.new(true)
end

Class Method Details

.open(config, url) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



42
43
44
45
46
# File 'lib/atatus/transport/connection/http.rb', line 42

def self.open(config, url)
  new(config).tap do |http|
    http.open(url)
  end
end

Instance Method Details

#close(reason) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/atatus/transport/connection/http.rb', line 71

def close(reason)
  return if closed?

  debug '%s: Closing request with reason %s', thread_str, reason
  @closed.make_true

  @wr&.close

  if @request&.join(5)
    @rd&.close
    return
  end

  @rd&.close

  return if @request.nil?

  error(
    '%s: APM Server not responding in time, terminating request',
    thread_str
  )
  @request.kill
end

#closed?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


95
96
97
# File 'lib/atatus/transport/connection/http.rb', line 95

def closed?
  @rd.closed? && @closed.true?
end

#get(url, headers: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



52
53
54
# File 'lib/atatus/transport/connection/http.rb', line 52

def get(url, headers: nil)
  request(:get, url, headers: headers)
end

#inspectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



99
100
101
102
103
104
105
# File 'lib/atatus/transport/connection/http.rb', line 99

def inspect
  format(
    '%s closed: %s>',
    super.split.first,
    closed?
  )
end

#open(url) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



36
37
38
39
40
# File 'lib/atatus/transport/connection/http.rb', line 36

def open(url)
  @closed.make_false
  @rd, @wr = ProxyPipe.pipe(compress: @config.http_compression?)
  @request = open_request_in_thread(url)
end

#post(url, body: nil, headers: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
# File 'lib/atatus/transport/connection/http.rb', line 48

def post(url, body: nil, headers: nil)
  request(:post, url, body: body, headers: headers)
end

#request(method, url, body: nil, headers: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



56
57
58
59
60
61
62
63
64
# File 'lib/atatus/transport/connection/http.rb', line 56

def request(method, url, body: nil, headers: nil)
  @client.send(
    method,
    url,
    body: body,
    headers: (headers ? @headers.merge(headers) : @headers).to_h,
    ssl_context: @config.ssl_context
  ).flush
end

#write(str) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



66
67
68
69
# File 'lib/atatus/transport/connection/http.rb', line 66

def write(str)
  @wr.write(str)
  @wr.bytes_sent
end