Class: HTTP::Message::Body
- Inherits:
-
Object
- Object
- HTTP::Message::Body
- Defined in:
- lib/httpclient/http.rb
Instance Attribute Summary collapse
-
#charset ⇒ Object
Returns the value of attribute charset.
-
#chunk_size ⇒ Object
Returns the value of attribute chunk_size.
-
#date ⇒ Object
Returns the value of attribute date.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #content ⇒ Object
- #dump(dev = '') ⇒ Object
-
#initialize(body = nil, date = nil, type = nil, charset = nil, boundary = nil) ⇒ Body
constructor
A new instance of Body.
- #set_content(body, boundary = nil) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(body = nil, date = nil, type = nil, charset = nil, boundary = nil) ⇒ Body
Returns a new instance of Body.
319 320 321 322 323 324 325 326 327 328 |
# File 'lib/httpclient/http.rb', line 319 def initialize(body = nil, date = nil, type = nil, charset = nil, boundary = nil) @body = nil @boundary = boundary set_content(body || '', boundary) @type = type @charset = charset @date = date @chunk_size = 4096 end |
Instance Attribute Details
#charset ⇒ Object
Returns the value of attribute charset.
317 318 319 |
# File 'lib/httpclient/http.rb', line 317 def charset @charset end |
#chunk_size ⇒ Object
Returns the value of attribute chunk_size.
317 318 319 |
# File 'lib/httpclient/http.rb', line 317 def chunk_size @chunk_size end |
#date ⇒ Object
Returns the value of attribute date.
317 318 319 |
# File 'lib/httpclient/http.rb', line 317 def date @date end |
#type ⇒ Object
Returns the value of attribute type.
317 318 319 |
# File 'lib/httpclient/http.rb', line 317 def type @type end |
Instance Method Details
#content ⇒ Object
355 356 357 |
# File 'lib/httpclient/http.rb', line 355 def content @body end |
#dump(dev = '') ⇒ Object
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/httpclient/http.rb', line 338 def dump(dev = '') if @body.respond_to?(:read) begin while true chunk = @body.read(@chunk_size) break if chunk.nil? dev << dump_chunk(chunk) end rescue EOFError end dev << (dump_last_chunk + CRLF) else dev << @body end dev end |
#set_content(body, boundary = nil) ⇒ Object
359 360 361 362 363 364 365 366 367 |
# File 'lib/httpclient/http.rb', line 359 def set_content(body, boundary = nil) if body.respond_to?(:read) @body = body elsif boundary @body = Message.create_query_multipart_str(body, boundary) else @body = Message.create_query_part_str(body) end end |
#size ⇒ Object
330 331 332 333 334 335 336 |
# File 'lib/httpclient/http.rb', line 330 def size if @body.respond_to?(:read) nil else @body.size end end |