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.
321 322 323 324 325 326 327 328 329 330 |
# File 'lib/httpclient/http.rb', line 321 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.
319 320 321 |
# File 'lib/httpclient/http.rb', line 319 def charset @charset end |
#chunk_size ⇒ Object
Returns the value of attribute chunk_size.
319 320 321 |
# File 'lib/httpclient/http.rb', line 319 def chunk_size @chunk_size end |
#date ⇒ Object
Returns the value of attribute date.
319 320 321 |
# File 'lib/httpclient/http.rb', line 319 def date @date end |
#type ⇒ Object
Returns the value of attribute type.
319 320 321 |
# File 'lib/httpclient/http.rb', line 319 def type @type end |
Instance Method Details
#content ⇒ Object
357 358 359 |
# File 'lib/httpclient/http.rb', line 357 def content @body end |
#dump(dev = '') ⇒ Object
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/httpclient/http.rb', line 340 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
361 362 363 364 365 366 367 368 369 |
# File 'lib/httpclient/http.rb', line 361 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
332 333 334 335 336 337 338 |
# File 'lib/httpclient/http.rb', line 332 def size if @body.respond_to?(:read) nil else @body.size end end |