class Opensaz::HTTPRequest
Constants
- CRLF
- SEPERATOR
Public Class Methods
new(content)
click to toggle source
# File lib/opensaz/http_request.rb, line 7 def initialize(content) raise "request_str couldn't be nil" if content == nil @content = content end
Public Instance Methods
body()
click to toggle source
# File lib/opensaz/http_request.rb, line 18 def body str = @content.split(CRLF * 2)[1..-1].join(CRLF * 2) str == "" ? nil : str end
headers()
click to toggle source
# File lib/opensaz/http_request.rb, line 12 def headers first_line = headers_str.split(CRLF)[0] following_lines = headers_str.split(CRLF)[1..-1] get_request_line(first_line).merge(get_headers(following_lines)) end
Private Instance Methods
get_headers(lines)
click to toggle source
# File lib/opensaz/http_request.rb, line 35 def get_headers(lines) # turn following lines of headers into hash lines.map do |x| a = x.split(SEPERATOR) [symbolize_it(a[0]), a[1]] end.to_h end
get_request_line(str)
click to toggle source
# File lib/opensaz/http_request.rb, line 29 def get_request_line(str) # turn first line of headers into hash a = str.split(" ") {method: a[0], path: a[1], version: a[2]} end
headers_str()
click to toggle source
# File lib/opensaz/http_request.rb, line 25 def headers_str @content.split(CRLF * 2)[0] end
symbolize_it(str)
click to toggle source
# File lib/opensaz/http_request.rb, line 43 def symbolize_it(str) # make it lower case # sub '-'' with '_' str.downcase.gsub('-', '_').to_sym end