Module: RUPNP::SSDP::HTTP
- Included in:
- Listener, MSearchResponder, Notifier, SearchResponder, Searcher, USearchResponder
- Defined in:
- lib/rupnp/ssdp/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
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rupnp/ssdp/http.rb', line 18 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
33 34 35 36 37 38 39 40 |
# File 'lib/rupnp/ssdp/http.rb', line 33 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
11 12 13 |
# File 'lib/rupnp/ssdp/http.rb', line 11 def is_http_status_ok?(sock) sock.readline =~ /\s*HTTP\/1.1 200 OK\r\n\z/i end |