Class: LogStash::Outputs::Http
- Inherits:
-
Base
- Object
- Base
- LogStash::Outputs::Http
- Includes:
- PluginMixins::HttpClient
- Defined in:
- lib/logstash/outputs/http.rb
Constant Summary collapse
- VALID_METHODS =
["put", "post", "patch", "delete", "get", "head"]
Instance Method Summary collapse
-
#receive(event) ⇒ Object
def register.
- #register ⇒ Object
Instance Method Details
#receive(event) ⇒ Object
def register
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/logstash/outputs/http.rb', line 92 def receive(event) body = event_body(event) # Block waiting for a token token = @request_tokens.pop # Send the request url = event.sprintf(@url) headers = event_headers(event) # Create an async request request = client.send(@http_method, url, body: body, headers: headers, async: true) # attach handlers before performing request request.on_complete do # Make sure we return the token to the pool @request_tokens << token end request.on_success do |response| if response.code < 200 || response.code > 299 log_failure( "Encountered non-200 HTTP code #{200}", :response_code => response.code, :url => url, :event => event) end end request.on_failure do |exception| log_failure("Could not fetch URL", :url => url, :method => @http_method, :body => body, :headers => headers, :message => exception., :class => exception.class.name, :backtrace => exception.backtrace ) end # Invoke it using the Manticore Executor (CachedThreadPool) directly request_async_background(request) end |
#register ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/logstash/outputs/http.rb', line 67 def register # Handle this deprecated option. TODO: remove the option @ssl_certificate_validation = @verify_ssl if @verify_ssl @http_method = @http_method.to_sym # We count outstanding requests with this queue # This queue tracks the requests to create backpressure # When this queue is empty no new requests may be sent, # tokens must be added back by the client on success @request_tokens = SizedQueue.new(@pool_max) @pool_max.times {|t| @request_tokens << true } @requests = Array.new if @content_type.nil? case @format when "form" ; @content_type = "application/x-www-form-urlencoded" when "json" ; @content_type = "application/json" when "message" ; @content_type = "text/plain" end end validate_format! end |