Class: Mxrb::Http::Server
- Inherits:
-
Object
- Object
- Mxrb::Http::Server
- Defined in:
- lib/mxrb/http/server.rb
Overview
Small embedded-Puma adapter for MXRB's loopback-only HTTP services.
Constant Summary collapse
- DEFAULT_MAX_THREADS =
5
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#puma ⇒ Object
readonly
Returns the value of attribute puma.
Instance Method Summary collapse
- #call(environment) ⇒ Object
-
#initialize(host:, port:, logger: nil, max_threads: DEFAULT_MAX_THREADS, &dispatcher) ⇒ Server
constructor
A new instance of Server.
- #shutdown ⇒ Object
- #start {|@puma| ... } ⇒ Object
Constructor Details
#initialize(host:, port:, logger: nil, max_threads: DEFAULT_MAX_THREADS, &dispatcher) ⇒ Server
Returns a new instance of Server.
45 46 47 48 49 50 51 52 53 |
# File 'lib/mxrb/http/server.rb', line 45 def initialize(host:, port:, logger: nil, max_threads: DEFAULT_MAX_THREADS, &dispatcher) raise ArgumentError, 'HTTP dispatcher is required' unless dispatcher @host = host.to_s @port = Integer(port) @dispatcher = dispatcher @logger = logger @max_threads = Integer(max_threads) end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
43 44 45 |
# File 'lib/mxrb/http/server.rb', line 43 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
43 44 45 |
# File 'lib/mxrb/http/server.rb', line 43 def port @port end |
#puma ⇒ Object (readonly)
Returns the value of attribute puma.
43 44 45 |
# File 'lib/mxrb/http/server.rb', line 43 def puma @puma end |
Instance Method Details
#call(environment) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/mxrb/http/server.rb', line 65 def call(environment) request = request_from(environment) response = Response.new @dispatcher.call(request, response) [response.status, response.headers, [response.body.to_s]] end |
#shutdown ⇒ Object
63 |
# File 'lib/mxrb/http/server.rb', line 63 def shutdown = @puma&.stop |
#start {|@puma| ... } ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/mxrb/http/server.rb', line 55 def start @puma = Puma::Server.new(method(:call), nil, ) @puma.add_tcp_listener(host, port) yield(@puma) if block_given? @thread = @puma.run @thread.join end |