Class: WEBrick::HTTPUtils::FormData
- Inherits:
-
String
- Object
- String
- WEBrick::HTTPUtils::FormData
- Defined in:
- lib/cyberweb/webrick/clone/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
Instance Attribute Summary collapse
-
#filename ⇒ Object
The filename of the form data part.
-
#name ⇒ Object
The name of the form data part.
-
#next_data ⇒ Object
writeonly
:nodoc:.
Instance Method Summary collapse
-
#<<(str) ⇒ Object
Adds
str
to this FormData which may be the body, a header or a header entry. -
#[](*key) ⇒ Object
Retrieves the header at the first entry in
key
. -
#append_data(data) ⇒ Object
Adds
data
at the end of the chain of entries. -
#each_data ⇒ Object
Yields each entry in this FormData.
-
#initialize(*args) ⇒ FormData
constructor
Creates a new FormData object.
-
#list ⇒ Object
(also: #to_ary)
Returns all the FormData as an Array.
-
#to_s ⇒ Object
This FormData’s body.
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
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/cyberweb/webrick/clone/webrick/httputils.rb', line 278 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
#filename ⇒ Object
The filename of the form data part
265 266 267 |
# File 'lib/cyberweb/webrick/clone/webrick/httputils.rb', line 265 def filename @filename end |
#name ⇒ Object
The name of the form data part
260 261 262 |
# File 'lib/cyberweb/webrick/clone/webrick/httputils.rb', line 260 def name @name end |
#next_data=(value) ⇒ Object
:nodoc:
267 268 269 |
# File 'lib/cyberweb/webrick/clone/webrick/httputils.rb', line 267 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
311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/cyberweb/webrick/clone/webrick/httputils.rb', line 311 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
297 298 299 300 301 302 303 |
# File 'lib/cyberweb/webrick/clone/webrick/httputils.rb', line 297 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.
331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/cyberweb/webrick/clone/webrick/httputils.rb', line 331 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_data ⇒ Object
Yields each entry in this FormData
346 347 348 349 350 351 352 353 |
# File 'lib/cyberweb/webrick/clone/webrick/httputils.rb', line 346 def each_data tmp = self while tmp next_data = tmp.next_data yield(tmp) tmp = next_data end end |
#list ⇒ Object Also known as: to_ary
Returns all the FormData as an Array
358 359 360 361 362 363 364 |
# File 'lib/cyberweb/webrick/clone/webrick/httputils.rb', line 358 def list ret = [] each_data{|data| ret << data.to_s } ret end |
#to_s ⇒ Object
This FormData’s body
374 375 376 |
# File 'lib/cyberweb/webrick/clone/webrick/httputils.rb', line 374 def to_s String.new(self) end |