Module: RUPNP::HTTP
- Included in:
- SSDP::Listener, SSDP::MSearchResponder, SSDP::Notifier, SSDP::SearchResponder, SSDP::Searcher, SSDP::USearchResponder
- Defined in:
- lib/rupnp/http.rb
Overview
HTTP module to provide some helper methods
Instance Method Summary collapse
-
#get_http_headers(sock) ⇒ Hash
Get HTTP headers from response.
-
#get_http_verb(sock) ⇒ nil, Hash
Get HTTP verb from HTTP request.
-
#is_http_status_ok?(sock) ⇒ Booelan
Return status from HTTP response.
Instance Method Details
#get_http_headers(sock) ⇒ Hash
Get HTTP headers from response
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rupnp/http.rb', line 17 def get_http_headers(sock) headers = {} sock.each_line do |l| l =~ /([\w\.-]+):\s*(.*)/ if $1 headers[$1.downcase] = $2.strip end end headers end |
#get_http_verb(sock) ⇒ nil, Hash
Get HTTP verb from HTTP request
32 33 34 35 36 37 38 39 |
# File 'lib/rupnp/http.rb', line 32 def get_http_verb(sock) str = sock.readline if str =~ /([\w-]+)\s+(.*)\s+HTTP\/(\d\.\d)/ {:verb => $1, :path => $2, :http_version => $3, :cmd => str} else nil end end |
#is_http_status_ok?(sock) ⇒ Booelan
Return status from HTTP response
10 11 12 |
# File 'lib/rupnp/http.rb', line 10 def is_http_status_ok?(sock) sock.readline =~ /\s*HTTP\/1.1 200 OK\r\n\z/i end |