Class: ProconBypassMan::ProconDisplay::HttpRequest
- Inherits:
-
Object
- Object
- ProconBypassMan::ProconDisplay::HttpRequest
- Defined in:
- lib/procon_bypass_man/procon_display/http_request.rb
Overview
NOTE Support GET only
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(headers) ⇒ HttpRequest
constructor
A new instance of HttpRequest.
- #path ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(headers) ⇒ HttpRequest
Returns a new instance of HttpRequest.
16 17 18 |
# File 'lib/procon_bypass_man/procon_display/http_request.rb', line 16 def initialize(headers) @headers = headers end |
Class Method Details
.parse(conn) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/procon_bypass_man/procon_display/http_request.rb', line 4 def self.parse(conn) headers = {} loop do line = conn.gets("\n")&.strip break if line.nil? || line.strip.empty? key, value = line.split(/:\s/, 2) headers[key] = value end new(headers) end |
Instance Method Details
#path ⇒ Object
20 21 22 23 24 25 |
# File 'lib/procon_bypass_man/procon_display/http_request.rb', line 20 def path request_method_and_path = @headers.detect { |key, _value| key.start_with?("GET") }.first if request_method_and_path =~ /(?:GET) ([^ ]+)/ && (path = $1) return path end end |
#to_hash ⇒ Object
27 28 29 |
# File 'lib/procon_bypass_man/procon_display/http_request.rb', line 27 def to_hash { "PATH" => path } end |