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 |
# 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) @reactor = Async::Reactor.new(nil, 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
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/fluent/plugin_helper/http_server/server.rb', line 56 def start(notify = nil) @logger.debug("Start async HTTP server listening #{@uri}") task = @reactor.run do @server.run if notify notify.push(:ready) end end task.stop @logger.debug('Finished HTTP server') end |
#stop ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/fluent/plugin_helper/http_server/server.rb', line 70 def stop @logger.debug('closing HTTP server') if @reactor @reactor.stop end end |