Class: Synthra::APIServer::RackRequest
- Inherits:
-
Object
- Object
- Synthra::APIServer::RackRequest
- Defined in:
- lib/synthra/api_server.rb
Overview
Request adapter for Rack
Instance Method Summary collapse
- #client_ip ⇒ Object
- #headers ⇒ Object
-
#initialize(env) ⇒ RackRequest
constructor
A new instance of RackRequest.
- #json_body ⇒ Object
- #method ⇒ Object
- #options? ⇒ Boolean
- #path ⇒ Object
- #post? ⇒ Boolean
- #query_params ⇒ Object
Constructor Details
#initialize(env) ⇒ RackRequest
Returns a new instance of RackRequest.
655 656 657 658 |
# File 'lib/synthra/api_server.rb', line 655 def initialize(env) @env = env @request = Rack::Request.new(env) if defined?(Rack::Request) end |
Instance Method Details
#client_ip ⇒ Object
686 687 688 |
# File 'lib/synthra/api_server.rb', line 686 def client_ip @env["REMOTE_ADDR"] end |
#headers ⇒ Object
681 682 683 684 |
# File 'lib/synthra/api_server.rb', line 681 def headers @env.select { |k, _| k.start_with?("HTTP_") } .transform_keys { |k| k[5..].tr("_", "-").downcase } end |
#json_body ⇒ Object
690 691 692 693 694 |
# File 'lib/synthra/api_server.rb', line 690 def json_body body = @env["rack.input"]&.read @env["rack.input"]&.rewind JSON.parse(body || "{}") rescue {} end |
#method ⇒ Object
664 665 666 |
# File 'lib/synthra/api_server.rb', line 664 def method @env["REQUEST_METHOD"] end |
#options? ⇒ Boolean
668 669 670 |
# File 'lib/synthra/api_server.rb', line 668 def method == "OPTIONS" end |
#path ⇒ Object
660 661 662 |
# File 'lib/synthra/api_server.rb', line 660 def path @env["PATH_INFO"] end |
#post? ⇒ Boolean
672 673 674 |
# File 'lib/synthra/api_server.rb', line 672 def post? method == "POST" end |
#query_params ⇒ Object
676 677 678 679 |
# File 'lib/synthra/api_server.rb', line 676 def query_params return {} unless @request @request.params.transform_keys(&:to_sym) end |