Module: Fluent::PluginHelper::HttpServer

Includes:
Configurable, Thread
Defined in:
lib/fluent/plugin_helper/http_server.rb,
lib/fluent/plugin_helper/http_server/app.rb,
lib/fluent/plugin_helper/http_server/router.rb,
lib/fluent/plugin_helper/http_server/server.rb,
lib/fluent/plugin_helper/http_server/methods.rb,
lib/fluent/plugin_helper/http_server/request.rb,
lib/fluent/plugin_helper/http_server/compat/server.rb,
lib/fluent/plugin_helper/http_server/ssl_context_builder.rb,
lib/fluent/plugin_helper/http_server/compat/webrick_handler.rb,
lib/fluent/plugin_helper/http_server/compat/ssl_context_extractor.rb

Defined Under Namespace

Modules: Compat, Methods Classes: App, Request, Router, SSLContextBuilder, Server

Constant Summary

Constants included from Configurable

Configurable::CONFIG_TYPE_REGISTRY

Constants included from Thread

Thread::THREAD_DEFAULT_WAIT_SECONDS, Thread::THREAD_SHUTDOWN_HARD_TIMEOUT_IN_TESTS

Instance Attribute Summary

Attributes included from Thread

#_threads

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Configurable

#config, #configure, #configure_proxy_generate, #configured_section_create, lookup_type, register_type

Methods included from Thread

#after_shutdown, #close, #terminate, #thread_create, #thread_current_running?, #thread_exist?, #thread_running?, #thread_started?, #thread_wait_until_start, #thread_wait_until_stop

Class Method Details

.included(mod) ⇒ Object

stop : stop http server and mark callback thread as stopped shutdown : [-] close : correct stopped threads terminate: kill thread



40
41
42
# File 'lib/fluent/plugin_helper/http_server.rb', line 40

def self.included(mod)
  mod.include Fluent::PluginHelper::Server::ServerTransportParams
end

Instance Method Details

#create_http_server(title, addr:, port:, logger:, default_app: nil, proto: nil, tls_opts: nil, &block) ⇒ Object



49
50
51
52
# File 'lib/fluent/plugin_helper/http_server.rb', line 49

def create_http_server(title, addr:, port:, logger:, default_app: nil, proto: nil, tls_opts: nil, &block)
  logger.warn('this method is deprecated. Use #http_server_create_http_server instead')
  http_server_create_http_server(title, addr: addr, port: port, logger: logger, default_app: default_app, proto: proto, tls_opts: tls_opts, &block)
end

#http_server_create_http_server(title, addr:, port:, logger:, default_app: nil, proto: nil, tls_opts: nil, &block) ⇒ Object

Parameters:

  • title (Symbol)

    the thread name. this value should be unique.

  • addr (String)

    Listen address

  • port (String)

    Listen port

  • logger (Logger)

    logger used in this server

  • default_app (Object) (defaults to: nil)

    This method must have #call.

  • proto (Symbol) (defaults to: nil)

    :tls or :tcp

  • tls_opts (Hash) (defaults to: nil)

    options for TLS.



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.rb', line 61

def http_server_create_http_server(title, addr:, port:, logger:, default_app: nil, proto: nil, tls_opts: nil, &block)
  unless block_given?
    raise ArgumentError, 'BUG: callback not specified'
  end

  if proto == :tls || (@transport_config && @transport_config.protocol == :tls)
    http_server_create_https_server(title, addr: addr, port: port, logger: logger, default_app: default_app, tls_opts: tls_opts, &block)
  else
    @_http_server = HttpServer::Server.new(addr: addr, port: port, logger: logger, default_app: default_app) do |serv|
      yield(serv)
    end

    _block_until_http_server_start do |notify|
      thread_create(title) do
        @_http_server.start(notify)
      end
    end
  end
end

#http_server_create_https_server(title, addr:, port:, logger:, default_app: nil, tls_opts: nil) ⇒ Object

Parameters:

  • title (Symbol)

    the thread name. this value should be unique.

  • addr (String)

    Listen address

  • port (String)

    Listen port

  • logger (Logger)

    logger used in this server

  • default_app (Object) (defaults to: nil)

    This method must have #call.

  • tls_opts (Hash) (defaults to: nil)

    options for TLS.



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/fluent/plugin_helper/http_server.rb', line 87

def http_server_create_https_server(title, addr:, port:, logger:, default_app: nil, tls_opts: nil)
  topt =
    if tls_opts
      _http_server_overwrite_config(@transport_config, tls_opts)
    else
      @transport_config
    end
  ctx = Fluent::PluginHelper::HttpServer::SSLContextBuilder.new($log).build(topt)

  @_http_server = HttpServer::Server.new(addr: addr, port: port, logger: logger, default_app: default_app, tls_context: ctx) do |serv|
    yield(serv)
  end

  _block_until_http_server_start do |notify|
    thread_create(title) do
      @_http_server.start(notify)
    end
  end
end

#initializeObject



44
45
46
47
# File 'lib/fluent/plugin_helper/http_server.rb', line 44

def initialize(*)
  super
  @_http_server = nil
end

#stopObject



107
108
109
110
111
112
113
# File 'lib/fluent/plugin_helper/http_server.rb', line 107

def stop
  if @_http_server
    @_http_server.stop
  end

  super
end