Class: HTTP::Message::Body

Inherits:
Object
  • Object
show all
Defined in:
lib/http-access2/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.



293
294
295
296
297
298
299
300
301
302
# File 'lib/http-access2/http.rb', line 293

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.



291
292
293
# File 'lib/http-access2/http.rb', line 291

def charset
  @charset
end

#chunk_sizeObject

Returns the value of attribute chunk_size.



291
292
293
# File 'lib/http-access2/http.rb', line 291

def chunk_size
  @chunk_size
end

#dateObject

Returns the value of attribute date.



291
292
293
# File 'lib/http-access2/http.rb', line 291

def date
  @date
end

#typeObject

Returns the value of attribute type.



291
292
293
# File 'lib/http-access2/http.rb', line 291

def type
  @type
end

Instance Method Details

#contentObject



329
330
331
# File 'lib/http-access2/http.rb', line 329

def content
  @body
end

#dump(dev = '') ⇒ Object



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/http-access2/http.rb', line 312

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



333
334
335
336
337
338
339
340
341
# File 'lib/http-access2/http.rb', line 333

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



304
305
306
307
308
309
310
# File 'lib/http-access2/http.rb', line 304

def size
  if @body.respond_to?(:read)
	nil
  else
	@body.size
  end
end