Class: Rbkb::Http::Body
- Inherits:
-
String
- Object
- String
- Rbkb::Http::Body
- Includes:
- CommonInterface
- Defined in:
- lib/rbkb/http/body.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#expect_length ⇒ Object
readonly
Returns the value of attribute expect_length.
Class Method Summary collapse
Instance Method Summary collapse
-
#capture(str) {|str| ... } ⇒ Object
The capture method is used when parsing HTTP requests/responses.
- #capture_complete? ⇒ Boolean
- #data ⇒ Object
-
#data=(str) ⇒ Object
Sets internal raw string data without any HTTP decoration.
-
#get_content_length ⇒ Object
(also: #content_length)
Returns the content length from the HTTP base object if there is one and content-length is available.
- #get_content_type ⇒ Object (also: #content_type)
-
#initialize(str = nil, opts = nil) {|_self| ... } ⇒ Body
constructor
A new instance of Body.
-
#reset_capture ⇒ Object
This method will non-destructively reset the capture state on this object.
-
#reset_capture! ⇒ Object
This method will destructively reset the capture state on this object.
-
#to_raw ⇒ Object
The to_raw method is used when writing HTTP requests/responses.
Methods included from CommonInterface
Constructor Details
#initialize(str = nil, opts = nil) {|_self| ... } ⇒ Body
Returns a new instance of Body.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rbkb/http/body.rb', line 13 def initialize(str=nil, opts=nil) self.opts = opts if Body === str self.replace(str) @opts = str.opts.merge(@opts) elsif String === str super(str) else super() end yield(self) if block_given? end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
40 41 42 |
# File 'lib/rbkb/http/body.rb', line 40 def base @base end |
#expect_length ⇒ Object (readonly)
Returns the value of attribute expect_length.
11 12 13 |
# File 'lib/rbkb/http/body.rb', line 11 def expect_length @expect_length end |
Class Method Details
.parse(str) ⇒ Object
7 8 9 |
# File 'lib/rbkb/http/body.rb', line 7 def self.parse(str) new().capture(str) end |
Instance Method Details
#capture(str) {|str| ... } ⇒ Object
The capture method is used when parsing HTTP requests/responses. This can and probably should be overridden in derived classes.
29 30 31 32 |
# File 'lib/rbkb/http/body.rb', line 29 def capture(str) yield(str) if block_given? self.data=(str) end |
#capture_complete? ⇒ Boolean
87 88 89 |
# File 'lib/rbkb/http/body.rb', line 87 def capture_complete? not @expect_length end |
#data ⇒ Object
50 51 52 |
# File 'lib/rbkb/http/body.rb', line 50 def data self end |
#data=(str) ⇒ Object
Sets internal raw string data without any HTTP decoration.
55 56 57 |
# File 'lib/rbkb/http/body.rb', line 55 def data=(str) self.replace(str.to_s) end |
#get_content_length ⇒ Object Also known as: content_length
Returns the content length from the HTTP base object if there is one and content-length is available.
61 62 63 |
# File 'lib/rbkb/http/body.rb', line 61 def get_content_length @base.content_length if @base end |
#get_content_type ⇒ Object Also known as: content_type
66 67 68 |
# File 'lib/rbkb/http/body.rb', line 66 def get_content_type @base.content_type if @base end |
#reset_capture ⇒ Object
This method will non-destructively reset the capture state on this object. It is non-destructive in that it will not affect existing captured data if present.
74 75 76 77 |
# File 'lib/rbkb/http/body.rb', line 74 def reset_capture @expect_length = nil @base.reset_capture() if @base and @base.capture_complete? end |
#reset_capture! ⇒ Object
This method will destructively reset the capture state on this object. This method is destructive in that it will clear any previously captured data.
82 83 84 85 |
# File 'lib/rbkb/http/body.rb', line 82 def reset_capture! reset_capture() self.data="" end |
#to_raw ⇒ Object
The to_raw method is used when writing HTTP requests/responses. This can and probably should be overridden in derived classes.
36 37 38 |
# File 'lib/rbkb/http/body.rb', line 36 def to_raw (block_given?) ? yield(self.data) : self.data end |