Class: HTTP::Message::Body

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#charsetObject

Returns the value of attribute charset.



317
318
319
# File 'lib/httpclient/http.rb', line 317

def charset
  @charset
end

#chunk_sizeObject

Returns the value of attribute chunk_size.



317
318
319
# File 'lib/httpclient/http.rb', line 317

def chunk_size
  @chunk_size
end

#dateObject

Returns the value of attribute date.



317
318
319
# File 'lib/httpclient/http.rb', line 317

def date
  @date
end

#typeObject

Returns the value of attribute type.



317
318
319
# File 'lib/httpclient/http.rb', line 317

def type
  @type
end

Instance Method Details

#contentObject



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

#sizeObject



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