Class: WEBrick::HTTPUtils::FormData (Ruby 2.2.4)
Description: Class : WEBrick::HTTPUtils::FormData - Ruby 2.2.4

- Home
- Core 2.2.4
- Std-lib 2.2.4
- Downloads

Support for the Ruby 2.2 series has ended. See here for reference.

### Home Classes Methods

### In Files

- webrick/httputils.rb

### Parent

String

### Methods

- ::new
- #<<
- #[]
- #append_data
- #each_data
- #list
- #to_ary
- #to_s

### Class/Module Index

Quicksearch

- Dir
- Errno
- Errno::ECONNABORTED
- Errno::ECONNRESET
- Errno::EPROTO
- File
- Object
- WEBrick
- WEBrick::AccessLog
- WEBrick::AccessLog::AccessLogError
- WEBrick::BasicLog
- WEBrick::CGI
- WEBrick::Config
- WEBrick::Config::OpenSSL
- WEBrick::Cookie
- WEBrick::Daemon
- WEBrick::GenericServer
- WEBrick::HTMLUtils
- WEBrick::HTTPAuth
- WEBrick::HTTPAuth::Authenticator
- WEBrick::HTTPAuth::BasicAuth
- WEBrick::HTTPAuth::DigestAuth
- WEBrick::HTTPAuth::Htdigest
- WEBrick::HTTPAuth::Htgroup
- WEBrick::HTTPAuth::Htpasswd
- WEBrick::HTTPAuth::ProxyAuthenticator
- WEBrick::HTTPAuth::ProxyBasicAuth
- WEBrick::HTTPAuth::ProxyDigestAuth
- WEBrick::HTTPAuth::UserDB
- WEBrick::HTTPProxyServer
- WEBrick::HTTPRequest
- WEBrick::HTTPResponse
- WEBrick::HTTPServer
- WEBrick::HTTPServerError
- WEBrick::HTTPServlet
- WEBrick::HTTPServlet::AbstractServlet
- WEBrick::HTTPServlet::CGIHandler
- WEBrick::HTTPServlet::DefaultFileHandler
- WEBrick::HTTPServlet::ERBHandler
- WEBrick::HTTPServlet::FileHandler
- WEBrick::HTTPServlet::HTTPServletError
- WEBrick::HTTPServlet::ProcHandler
- WEBrick::HTTPStatus
- WEBrick::HTTPStatus::ClientError
- WEBrick::HTTPStatus::EOFError
- WEBrick::HTTPStatus::Error
- WEBrick::HTTPStatus::Info
- WEBrick::HTTPStatus::Redirect
- WEBrick::HTTPStatus::ServerError
- WEBrick::HTTPStatus::Status
- WEBrick::HTTPStatus::Success
- WEBrick::HTTPUtils
- WEBrick::HTTPUtils::FormData
- WEBrick::HTTPVersion
- WEBrick::Log
- WEBrick::ServerError
- WEBrick::SimpleServer
- WEBrick::Utils
- WEBrick::Utils::TimeoutHandler
- WEBrick::Utils::TimeoutHandler::Thread

No matching classes.

# WEBrick::HTTPUtils::FormData

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

### Attributes

filename[RW]

The filename of the form data part

name[RW]

The name of the form data part

### Public Class Methods

new(*args) click to toggle source

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

                   # File webrick/httputils.rb, line 264
    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

### Public Instance Methods

<<(str) click to toggle source

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

                   # File webrick/httputils.rb, line 297
    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) click to toggle source

Retrieves the header at the first entry in `key`

                   # File webrick/httputils.rb, line 283
    def [](*key)
      begin
        @header[key[0].downcase].join(", ")
      rescue StandardError, NameError
        super
      end
    end

append_data(data) click to toggle source

Adds `data` at the end of the chain of entries

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

                   # File webrick/httputils.rb, line 317
    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() click to toggle source

Yields each entry in this FormData

                   # File webrick/httputils.rb, line 332
    def each_data
      tmp = self
      while tmp
        next_data = tmp.next_data
        yield(tmp)
        tmp = next_data
      end
    end

list() click to toggle source

Returns all the FormData as an Array

                   # File webrick/httputils.rb, line 344
    def list
      ret = []
      each_data{|data|
        ret << data.to_s
      }
      ret
    end

Also aliased as: to_ary
to_ary() click to toggle source

A FormData will behave like an Array

Alias for: list
to_s() click to toggle source

This FormData's body

                   # File webrick/httputils.rb, line 360
    def to_s
      String.new(self)
    end