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 =
30
Instance Attribute Summary collapse
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#ssl ⇒ Object
readonly
Returns the value of attribute ssl.
-
#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(&block) ⇒ Object
- #post(env) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(hostname, port, options = {}) ⇒ Net
Returns a new instance of Net.
19 20 21 22 23 24 |
# File 'lib/ddtrace/transport/http/adapters/net.rb', line 19 def initialize(hostname, port, = {}) @hostname = hostname @port = port @timeout = [:timeout] || DEFAULT_TIMEOUT @ssl = .key?(:ssl) ? [:ssl] == true : false end |
Instance Attribute Details
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
11 12 13 |
# File 'lib/ddtrace/transport/http/adapters/net.rb', line 11 def hostname @hostname end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
11 12 13 |
# File 'lib/ddtrace/transport/http/adapters/net.rb', line 11 def port @port end |
#ssl ⇒ Object (readonly)
Returns the value of attribute ssl.
11 12 13 |
# File 'lib/ddtrace/transport/http/adapters/net.rb', line 11 def ssl @ssl end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
11 12 13 |
# File 'lib/ddtrace/transport/http/adapters/net.rb', line 11 def timeout @timeout end |
Instance Method Details
#call(env) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/ddtrace/transport/http/adapters/net.rb', line 38 def call(env) if respond_to?(env.verb) send(env.verb, env) else raise UnknownHTTPMethod, env end end |
#open(&block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ddtrace/transport/http/adapters/net.rb', line 26 def open(&block) # DEV Initializing +Net::HTTP+ directly help us avoid expensive # options processing done in +Net::HTTP.start+: # https://github.com/ruby/ruby/blob/b2d96abb42abbe2e01f010ffc9ac51f0f9a50002/lib/net/http.rb#L614-L618 req = ::Net::HTTP.new(hostname, port, nil) req.use_ssl = ssl req.open_timeout = req.read_timeout = timeout req.start(&block) end |
#post(env) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ddtrace/transport/http/adapters/net.rb', line 46 def post(env) post = nil if env.form.nil? || env.form.empty? post = ::Net::HTTP::Post.new(env.path, env.headers) post.body = env.body else post = ::Datadog::Vendor::Net::HTTP::Post::Multipart.new( env.path, env.form, env.headers ) end # Connect and send the request http_response = open do |http| http.request(post) end # Build and return response Response.new(http_response) end |
#url ⇒ Object
69 70 71 |
# File 'lib/ddtrace/transport/http/adapters/net.rb', line 69 def url "http://#{hostname}:#{port}?timeout=#{timeout}" end |