Class: Mu::Curl::Verify::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/mu/curl/verify.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Request

Returns a new instance of Request.



32
33
34
35
36
37
38
39
# File 'lib/mu/curl/verify.rb', line 32

def initialize json
    rq = Request.parse json['bytes'][0]['data']
    @line = rq[:line]
    @method, @url, _ = rq[:line].split(/\s+/, 3)
    @content = rq[:content]
    @headers = Hash.new
    rq[:headers].each { |h| @headers[h[:key]] = h[:val] }
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



30
31
32
# File 'lib/mu/curl/verify.rb', line 30

def content
  @content
end

#headersObject (readonly)

Returns the value of attribute headers.



29
30
31
# File 'lib/mu/curl/verify.rb', line 29

def headers
  @headers
end

#lineObject (readonly)

Returns the value of attribute line.



26
27
28
# File 'lib/mu/curl/verify.rb', line 26

def line
  @line
end

#methodObject (readonly)

Returns the value of attribute method.



27
28
29
# File 'lib/mu/curl/verify.rb', line 27

def method
  @method
end

#urlObject (readonly)

Returns the value of attribute url.



28
29
30
# File 'lib/mu/curl/verify.rb', line 28

def url
  @url
end

Class Method Details

.parse(data) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mu/curl/verify.rb', line 5

def self.parse data
    ios = StringIO.new data.unpack('m')[0]
    rqrs = { :line => '', :headers => [], :content => '' }
    while true
        line = ios.readline
        break if not line or line == "\r\n"
        if rqrs[:line].empty?
            rqrs[:line] = line.chomp
        else
            if /^([^:]+):(.*)/ =~ line
                key = $1
                val = $2.strip
                rqrs[:headers] << { :line => line.chomp, :key => key, :val => val }
            end
        end
    end

    rqrs[:content] = ios.read
    return rqrs
end