Module: Semian::NetHTTP

Includes:
Adapter
Defined in:
lib/semian/net_http.rb

Defined Under Namespace

Modules: ClassMethods Classes: SemianConfigurationChangedError

Constant Summary collapse

ResourceBusyError =
::Net::ResourceBusyError
CircuitOpenError =
::Net::CircuitOpenError
DEFAULT_ERRORS =
[
  ::Timeout::Error, # includes ::Net::ReadTimeout and ::Net::OpenTimeout
  ::SocketError,
  ::Net::HTTPBadResponse,
  ::Net::HTTPHeaderSyntaxError,
  ::Net::ProtocolError,
  ::EOFError,
  ::IOError,
  ::SystemCallError, # includes ::Errno::EINVAL, ::Errno::ECONNRESET,
  # ::Errno::ECONNREFUSED, ::Errno::ETIMEDOUT, and more
].freeze

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Adapter

#clear_semian_resource, #semian_resource

Class Attribute Details

.exceptionsObject

rubocop:disable ThreadSafety/ClassAndModuleAttributes



58
59
60
# File 'lib/semian/net_http.rb', line 58

def exceptions
  @exceptions
end

.semian_configurationObject

Returns the value of attribute semian_configuration.



59
60
61
# File 'lib/semian/net_http.rb', line 59

def semian_configuration
  @semian_configuration
end

Class Method Details

.reset_exceptionsObject

rubocop:enable ThreadSafety/ClassInstanceVariable



74
75
76
# File 'lib/semian/net_http.rb', line 74

def reset_exceptions
  self.exceptions = Semian::NetHTTP::DEFAULT_ERRORS.dup
end

.retrieve_semian_configuration(host, port) ⇒ Object



69
70
71
# File 'lib/semian/net_http.rb', line 69

def retrieve_semian_configuration(host, port)
  @semian_configuration.call(host, port) if @semian_configuration.respond_to?(:call)
end

Instance Method Details

#connectObject



96
97
98
99
100
101
102
# File 'lib/semian/net_http.rb', line 96

def connect
  with_cleared_dynamic_options do
    return super if disabled?

    acquire_semian_resource(adapter: :http, scope: :connection) { super }
  end
end

#disabled?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/semian/net_http.rb', line 92

def disabled?
  raw_semian_options.nil? || @semian_enabled == false
end

#raw_semian_optionsObject



81
82
83
84
85
86
# File 'lib/semian/net_http.rb', line 81

def raw_semian_options
  @raw_semian_options ||= begin
    @raw_semian_options = Semian::NetHTTP.retrieve_semian_configuration(address, port)
    @raw_semian_options = @raw_semian_options.dup unless @raw_semian_options.nil?
  end
end

#resource_exceptionsObject



88
89
90
# File 'lib/semian/net_http.rb', line 88

def resource_exceptions
  Semian::NetHTTP.exceptions
end

#semian_identifierObject



33
34
35
# File 'lib/semian/net_http.rb', line 33

def semian_identifier
  "nethttp_#{raw_semian_options[:name]}"
end

#transport_requestObject



104
105
106
107
108
109
110
111
112
# File 'lib/semian/net_http.rb', line 104

def transport_request(*)
  with_cleared_dynamic_options do
    return super if disabled?

    acquire_semian_resource(adapter: :http, scope: :query) do
      handle_error_responses(super)
    end
  end
end

#with_resource_timeout(timeout) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/semian/net_http.rb', line 114

def with_resource_timeout(timeout)
  prev_read_timeout = read_timeout
  prev_open_timeout = open_timeout
  begin
    self.read_timeout = timeout
    self.open_timeout = timeout
    yield
  ensure
    self.read_timeout = prev_read_timeout
    self.open_timeout = prev_open_timeout
  end
end