Class: Datadog::Transport::HTTP::Adapters::Net
- Inherits:
-
Object
- Object
- Datadog::Transport::HTTP::Adapters::Net
- Defined in:
- lib/ddtrace/transport/http/adapters/net.rb
Overview
Adapter for Net::HTTP
Direct Known Subclasses
Defined Under Namespace
Classes: Response, UnknownHTTPMethod
Constant Summary collapse
- DEFAULT_TIMEOUT =
1
Instance Attribute Summary collapse
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(hostname, port, options = {}) ⇒ Net
constructor
A new instance of Net.
- #open ⇒ Object
- #post(env) ⇒ Object
Constructor Details
#initialize(hostname, port, options = {}) ⇒ Net
Returns a new instance of Net.
16 17 18 19 20 |
# File 'lib/ddtrace/transport/http/adapters/net.rb', line 16 def initialize(hostname, port, = {}) @hostname = hostname @port = port @timeout = [:timeout] || DEFAULT_TIMEOUT end |
Instance Attribute Details
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
9 10 11 |
# File 'lib/ddtrace/transport/http/adapters/net.rb', line 9 def hostname @hostname end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
9 10 11 |
# File 'lib/ddtrace/transport/http/adapters/net.rb', line 9 def port @port end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
9 10 11 |
# File 'lib/ddtrace/transport/http/adapters/net.rb', line 9 def timeout @timeout end |
Instance Method Details
#call(env) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/ddtrace/transport/http/adapters/net.rb', line 29 def call(env) if respond_to?(env.verb) send(env.verb, env) else raise UnknownHTTPMethod, env end end |
#open ⇒ Object
22 23 24 25 26 27 |
# File 'lib/ddtrace/transport/http/adapters/net.rb', line 22 def open # Open connection ::Net::HTTP.start(hostname, port, open_timeout: timeout, read_timeout: timeout) do |http| yield(http) end end |
#post(env) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ddtrace/transport/http/adapters/net.rb', line 37 def post(env) post = ::Net::HTTP::Post.new(env.path, env.headers) post.body = env.body # Connect and send the request http_response = open do |http| http.request(post) end # Build and return response Response.new(http_response) end |