Sha256: 06ccce6ec43959ee88b0d3e195512eaeac3097d643257a12e66b23627473fb48

Contents?: true

Size: 1.53 KB

Versions: 3

Compression:

Stored size: 1.53 KB

Contents

class CGI #:nodoc:
  # Add @request.env['RAW_POST_DATA'] for the vegans.
  module QueryExtension
    # Initialize the data from the query.
    #
    # Handles multipart forms (in particular, forms that involve file uploads).
    # Reads query parameters in the @params field, and cookies into @cookies.
    def initialize_query()
      if boundary = multipart_form_boundary
        @multipart = true
        @params = read_multipart(boundary, Integer(env_table['CONTENT_LENGTH']))
      else
        @multipart = false
        @params = CGI::parse(read_query_params)
      end
      
      @cookies = CGI::Cookie::parse((env_table['HTTP_COOKIE'] || env_table['COOKIE']))
    end

    private
      MULTIPART_FORM_BOUNDARY_RE = %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?|n #"

      def multipart_form_boundary        
        if env_table['REQUEST_METHOD'] == 'POST'
          MULTIPART_FORM_BOUNDARY_RE.match(env_table['CONTENT_TYPE']).to_a.pop
        end
      end

      def read_query_params
        case env_table['REQUEST_METHOD']
          when 'GET', 'HEAD'
            if defined? MOD_RUBY              
              Apache::request.args || ''
            else
              env_table['QUERY_STRING'] || ''
            end
          when 'POST'
            stdinput.binmode if stdinput.respond_to?(:binmode)
            content = stdinput.read(Integer(env_table['CONTENT_LENGTH'])) || ''
            env_table['RAW_POST_DATA'] = content.freeze
          else
            read_from_cmdline
          end
      end
  end # module QueryExtension
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
actionpack-1.5.0 lib/action_controller/cgi_ext/raw_post_data_fix.rb
actionpack-1.5.1 lib/action_controller/cgi_ext/raw_post_data_fix.rb
actionpack-1.6.0 lib/action_controller/cgi_ext/raw_post_data_fix.rb