Class: WEBrick::HTTPUtils::FormData

Inherits:
String
  • Object
show all
Defined in:
lib/webrick/httputils.rb

Overview

###

Constant Summary collapse

EmptyRawHeader =
[].freeze
EmptyHeader =
{}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ FormData

Returns a new instance of FormData.



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/webrick/httputils.rb', line 210

def initialize(*args)
  @name = @filename = @next_data = nil
  if args.empty?
    @raw_header = []
    @header = nil
    super("")
  else
    @raw_header = EmptyRawHeader
    @header = EmptyHeader 
    super(args.shift)
    unless args.empty?
      @next_data = self.class.new(*args)
    end
  end
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename



207
208
209
# File 'lib/webrick/httputils.rb', line 207

def filename
  @filename
end

#nameObject

Returns the value of attribute name



207
208
209
# File 'lib/webrick/httputils.rb', line 207

def name
  @name
end

#next_data=(value) ⇒ Object

Sets the attribute next_data

Parameters:

  • value

    the value to set the attribute next_data to.



207
208
209
# File 'lib/webrick/httputils.rb', line 207

def next_data=(value)
  @next_data = value
end

Instance Method Details

#<<(str) ⇒ Object



234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/webrick/httputils.rb', line 234

def <<(str)
  if @header
    super
  elsif str == CRLF
    @header = HTTPUtils::parse_header(@raw_header)
    if cd = self['content-disposition']
      if /\s+name="(.*?)"/ =~ cd then @name = $1 end
      if /\s+filename="(.*?)"/ =~ cd then @filename = $1 end
    end
  else
    @raw_header << str
  end
  self
end

#[](*key) ⇒ Object



226
227
228
229
230
231
232
# File 'lib/webrick/httputils.rb', line 226

def [](*key)
  begin
    @header[key[0].downcase].join(", ")
  rescue StandardError, NameError
    super
  end
end

#append_data(data) ⇒ Object



249
250
251
252
253
254
255
256
257
258
259
# File 'lib/webrick/httputils.rb', line 249

def append_data(data)
  tmp = self
  while tmp
    unless tmp.next_data 
      tmp.next_data = data
      break
    end
    tmp = tmp.next_data
  end
  self
end

#each_dataObject



261
262
263
264
265
266
267
268
# File 'lib/webrick/httputils.rb', line 261

def each_data
  tmp = self
  while tmp
    next_data = tmp.next_data
    yield(tmp)
    tmp = next_data
  end
end

#listObject Also known as: to_ary



270
271
272
273
274
275
276
# File 'lib/webrick/httputils.rb', line 270

def list
  ret = []
  each_data{|data|
    ret << data.to_s
  }
  ret
end

#to_sObject



280
281
282
# File 'lib/webrick/httputils.rb', line 280

def to_s
  String.new(self)
end