Module: RUPNP::HTTP

Overview

HTTP module to provide some helper methods

Author:

  • Sylvain Daubert

Instance Method Summary collapse

Instance Method Details

#get_http_headers(sock) ⇒ Hash

Get HTTP headers from response

Parameters:

  • sock (IO)

Returns:

  • (Hash)

    keys are downcase header name strings



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

Parameters:

  • sock (IO)

Returns:

  • (nil, Hash)

    keys are :verb, :path, :http_version and :cmd (all line)



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

Parameters:

  • sock (IO)

Returns:

  • (Booelan)


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