Class: SpiderGazelle::Spider::Http1::Callbacks

Inherits:
Object
  • Object
show all
Defined in:
lib/spider-gazelle/spider/http1.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCallbacks

Returns a new instance of Callbacks.



11
12
13
14
# File 'lib/spider-gazelle/spider/http1.rb', line 11

def initialize
    @parser = ::HttpParser::Parser.new self
    @logger = Logger.instance
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



17
18
19
# File 'lib/spider-gazelle/spider/http1.rb', line 17

def connection
  @connection
end

#parserObject (readonly)

Returns the value of attribute parser.



18
19
20
# File 'lib/spider-gazelle/spider/http1.rb', line 18

def parser
  @parser
end

Instance Method Details

#on_body(parser, data) ⇒ Object



57
58
59
# File 'lib/spider-gazelle/spider/http1.rb', line 57

def on_body(parser, data)
    @connection.parsing.body << data
end

#on_header_field(parser, header) ⇒ Object



29
30
31
32
# File 'lib/spider-gazelle/spider/http1.rb', line 29

def on_header_field(parser, header)
    req = @connection.parsing
    req.header.frozen? ? req.header = header : req.header << header
end

#on_header_value(parser, value) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/spider-gazelle/spider/http1.rb', line 34

def on_header_value(parser, value)
    req = @connection.parsing
    if req.header.frozen?
        req.env[req.header] << value
    else
        header = req.header
        header.upcase!
        header.gsub!('-', '_')
        header.prepend('HTTP_')
        header.freeze
        if req.env[header]
            req.env[header] << ', '
            req.env[header] << value
        else
            req.env[header] = String.new(value)
        end
    end
end

#on_headers_complete(parser) ⇒ Object



53
54
55
# File 'lib/spider-gazelle/spider/http1.rb', line 53

def on_headers_complete(parser)
    @connection.headers_complete
end

#on_message_begin(parser) ⇒ Object



21
22
23
# File 'lib/spider-gazelle/spider/http1.rb', line 21

def on_message_begin(parser)
    @connection.start_parsing
end

#on_message_complete(parser) ⇒ Object



61
62
63
# File 'lib/spider-gazelle/spider/http1.rb', line 61

def on_message_complete(parser)
    @connection.finished_parsing
end

#on_url(parser, url) ⇒ Object



25
26
27
# File 'lib/spider-gazelle/spider/http1.rb', line 25

def on_url(parser, url)
    @connection.parsing.url << url
end