Class: WEBrick::HTTPUtils::FormData

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

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.



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/webrick/httputils.rb', line 213

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.



210
211
212
# File 'lib/webrick/httputils.rb', line 210

def filename
  @filename
end

#nameObject

Returns the value of attribute name.



210
211
212
# File 'lib/webrick/httputils.rb', line 210

def name
  @name
end

#next_data=(value) ⇒ Object

Sets the attribute next_data

Parameters:

  • value

    the value to set the attribute next_data to.



210
211
212
# File 'lib/webrick/httputils.rb', line 210

def next_data=(value)
  @next_data = value
end

Instance Method Details

#<<(str) ⇒ Object



237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/webrick/httputils.rb', line 237

def <<(str)
  if @header
    super
  elsif str == CRLF
    @header = HTTPUtils::parse_header(@raw_header.join)
    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



229
230
231
232
233
234
235
# File 'lib/webrick/httputils.rb', line 229

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

#append_data(data) ⇒ Object



252
253
254
255
256
257
258
259
260
261
262
# File 'lib/webrick/httputils.rb', line 252

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



264
265
266
267
268
269
270
271
# File 'lib/webrick/httputils.rb', line 264

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



273
274
275
276
277
278
279
# File 'lib/webrick/httputils.rb', line 273

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

#to_sObject



283
284
285
# File 'lib/webrick/httputils.rb', line 283

def to_s
  String.new(self)
end