Class: WEBrick::HTTPUtils::FormData

Inherits:
String show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/webrick-1.7.0/lib/webrick/httputils.rb

Overview

Stores multipart form data. FormData objects are created when WEBrick::HTTPUtils.parse_form_data is called.

Constant Summary collapse

EmptyRawHeader =

:nodoc:

[].freeze
EmptyHeader =

:nodoc:

{}.freeze

Constants inherited from String

String::BLANK_RE, String::ENCODED_BLANKS, String::ENCODING_BINARY

Constants included from Diff::LCS

Diff::LCS::BalancedCallbacks, Diff::LCS::PATCH_MAP, Diff::LCS::SequenceCallbacks, Diff::LCS::VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from String

#_blankslate_as_name, #acts_like_string?, #as_json, #at, #blank?, #camelize, #classify, #constantize, #dasherize, #deconstantize, #demodulize, #exclude?, #first, #foreign_key, #from, #html_safe, #humanize, #in_time_zone, #indent, #indent!, #inquiry, #is_utf8?, #last, #mb_chars, #parameterize, #pluralize, #remove, #remove!, #safe_constantize, #singularize, #squish, #squish!, #strip_heredoc, #tableize, #titleize, #to, #to_date, #to_datetime, #to_time, #to_xs, #truncate, #truncate_bytes, #truncate_words, #underscore, #upcase_first

Methods included from Diff::LCS

callbacks_for, #diff, diff, diff_traversal, #lcs, lcs, patch, #patch, #patch!, patch!, #patch_me, #sdiff, sdiff, #traverse_balanced, traverse_balanced, traverse_sequences, #traverse_sequences, #unpatch, #unpatch!, unpatch!, #unpatch_me

Constructor Details

#initialize(*args) ⇒ FormData

Creates a new FormData object.

args is an Array of form data entries. One FormData will be created for each entry.

This is called by WEBrick::HTTPUtils.parse_form_data for you



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/webrick-1.7.0/lib/webrick/httputils.rb', line 267

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

The filename of the form data part



254
255
256
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/webrick-1.7.0/lib/webrick/httputils.rb', line 254

def filename
  @filename
end

#nameObject

The name of the form data part



249
250
251
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/webrick-1.7.0/lib/webrick/httputils.rb', line 249

def name
  @name
end

#next_data=(value) ⇒ Object

:nodoc:



256
257
258
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/webrick-1.7.0/lib/webrick/httputils.rb', line 256

def next_data=(value)
  @next_data = value
end

Instance Method Details

#<<(str) ⇒ Object

Adds str to this FormData which may be the body, a header or a header entry.

This is called by WEBrick::HTTPUtils.parse_form_data for you



300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/webrick-1.7.0/lib/webrick/httputils.rb', line 300

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

Retrieves the header at the first entry in key



286
287
288
289
290
291
292
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/webrick-1.7.0/lib/webrick/httputils.rb', line 286

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

#append_data(data) ⇒ Object

Adds data at the end of the chain of entries

This is called by WEBrick::HTTPUtils.parse_form_data for you.



320
321
322
323
324
325
326
327
328
329
330
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/webrick-1.7.0/lib/webrick/httputils.rb', line 320

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

Yields each entry in this FormData



335
336
337
338
339
340
341
342
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/webrick-1.7.0/lib/webrick/httputils.rb', line 335

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

Returns all the FormData as an Array



347
348
349
350
351
352
353
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/webrick-1.7.0/lib/webrick/httputils.rb', line 347

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

#to_sObject

This FormData’s body



363
364
365
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/webrick-1.7.0/lib/webrick/httputils.rb', line 363

def to_s
  String.new(self)
end