Class: Fluent::PluginHelper::HttpServer::Server
- Inherits:
-
Object
- Object
- Fluent::PluginHelper::HttpServer::Server
- Defined in:
- lib/fluent/plugin_helper/http_server/server.rb
Instance Method Summary collapse
-
#initialize(addr:, port:, logger:, default_app: nil, tls_context: nil) ⇒ Server
constructor
A new instance of Server.
- #start(notify = nil) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(addr:, port:, logger:, default_app: nil, tls_context: nil) ⇒ Server
Returns a new instance of Server.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fluent/plugin_helper/http_server/server.rb', line 33 def initialize(addr:, port:, logger:, default_app: nil, tls_context: nil) @addr = addr @port = port @logger = logger # TODO: support http2 scheme = tls_context ? 'https' : 'http' @uri = URI("#{scheme}://#{@addr}:#{@port}").to_s @router = Router.new(default_app) @server_task = nil Console.logger = Fluent::Log::ConsoleAdapter.wrap(@logger) opts = if tls_context { ssl_context: tls_context } else {} end @server = Async::HTTP::Server.new(App.new(@router, @logger), Async::HTTP::Endpoint.parse(@uri, **opts)) if block_given? yield(self) end end |
Instance Method Details
#start(notify = nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/fluent/plugin_helper/http_server/server.rb', line 57 def start(notify = nil) Console.logger = Fluent::Log::ConsoleAdapter.wrap(@logger) @logger.debug("Start async HTTP server listening #{@uri}") Async do |task| Console.logger = Fluent::Log::ConsoleAdapter.wrap(@logger) @server_task = task.async do Console.logger = Fluent::Log::ConsoleAdapter.wrap(@logger) @server.run end if notify notify.push(:ready) end if async_v2? @server_task_queue = ::Thread::Queue.new @server_task_queue.pop @server_task&.stop end end @logger.debug('Finished HTTP server') end |
#stop ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/fluent/plugin_helper/http_server/server.rb', line 81 def stop @logger.debug('closing HTTP server') if async_v2? @server_task_queue&.push(:stop) else @server_task&.stop end end |