Class: Pytty::Daemon::Components::HttpHandler
- Inherits:
-
Object
- Object
- Pytty::Daemon::Components::HttpHandler
- Defined in:
- lib/pytty/daemon/components/http_handler.rb
Instance Method Summary collapse
- #handle ⇒ Object
-
#initialize(env) ⇒ HttpHandler
constructor
A new instance of HttpHandler.
Constructor Details
#initialize(env) ⇒ HttpHandler
Returns a new instance of HttpHandler.
9 10 11 |
# File 'lib/pytty/daemon/components/http_handler.rb', line 9 def initialize(env) @env = env end |
Instance Method Details
#handle ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/pytty/daemon/components/http_handler.rb', line 13 def handle req = Rack::Request.new(@env) body = begin JSON.parse(req.body.read) rescue end params = Mustermann.new('/:component(/?:id)?').params(req.path_info) case params.fetch("component") when "rm" id = params["id"] process_yield = Pytty::Daemon.yields[id] unless process_yield return [404, nil] else return [200, process_yield] end end case req.path_info when "/kill" p req return [200, {}] end obj = case req.path_info when "/run" Run.new cmd: body.dig("cmd") when "/stream" Stream.new cmd: body.dig("cmd") else raise "Unknown: #{req.path_info}" end obj.run end |