Class: HTTP::Response::Parser Private

Inherits:
Object
  • Object
show all
Defined in:
lib/http/response/parser.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: Handler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Parser.



11
12
13
14
15
# File 'lib/http/response/parser.rb', line 11

def initialize
  @handler = Handler.new(self)
  @parser = LLHttp::Parser.new(@handler, :type => :response)
  reset
end

Instance Attribute Details

#headersObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/http/response/parser.rb', line 9

def headers
  @headers
end

#http_versionObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/http/response/parser.rb', line 9

def http_version
  @http_version
end

#parserObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/http/response/parser.rb', line 9

def parser
  @parser
end

#status_codeObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/http/response/parser.rb', line 9

def status_code
  @status_code
end

Instance Method Details

#add(data) ⇒ Object Also known as: <<

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



28
29
30
31
32
33
34
# File 'lib/http/response/parser.rb', line 28

def add(data)
  parser << data

  self
rescue LLHttp::Error => e
  raise IOError, e.message
end

#add_body(chunk) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



60
61
62
63
64
65
66
# File 'lib/http/response/parser.rb', line 60

def add_body(chunk)
  if @chunk
    @chunk << chunk
  else
    @chunk = chunk
  end
end

#add_header(name, value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
# File 'lib/http/response/parser.rb', line 48

def add_header(name, value)
  @headers.add(name, value)
end

#finished?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


56
57
58
# File 'lib/http/response/parser.rb', line 56

def finished?
  @message_finished
end

#headers?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


44
45
46
# File 'lib/http/response/parser.rb', line 44

def headers?
  @header_finished
end

#mark_header_finishedObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



38
39
40
41
42
# File 'lib/http/response/parser.rb', line 38

def mark_header_finished
  @header_finished = true
  @status_code = @parser.status_code
  @http_version = "#{@parser.http_major}.#{@parser.http_minor}"
end

#mark_message_finishedObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



52
53
54
# File 'lib/http/response/parser.rb', line 52

def mark_message_finished
  @message_finished = true
end

#read(size) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/http/response/parser.rb', line 68

def read(size)
  return if @chunk.nil?

  if @chunk.bytesize <= size
    chunk  = @chunk
    @chunk = nil
  else
    chunk = @chunk.byteslice(0, size)
    @chunk[0, size] = ""
  end

  chunk
end

#resetObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



17
18
19
20
21
22
23
24
25
26
# File 'lib/http/response/parser.rb', line 17

def reset
  @parser.reset
  @handler.reset
  @header_finished = false
  @message_finished = false
  @headers = Headers.new
  @chunk = nil
  @status_code = nil
  @http_version = nil
end