lib/http/native_parser.rb
# The HTTP method string used. Will always be a string and all-capsed.
# Valid values are: "GET", "HEAD", "POST", "PUT", "DELETE".
# Other values will cause an exception since then we don't know
# whether the request has a body.
The HTTP method string used. Will always be a string and all-capsed.
The HTTP method string used . Will always be a string and all - capsed .
def parse_body_chunked(scanner)
      if (@chunk_remain)
        if (@chunk_remain > 0)
          addition = scanner.string[scanner.pos, @chunk_remain]
          scanner.pos += addition.length
          @chunk_remain -= addition.length
          @body_length += addition.length
          @body << addition if @body
          if (@body.length >= @options[:min_tempfile_size] && @body.kind_of?(StringIO))
            @body_str = @body.string
            @body = @options[:tempfile_class].new("http_parser")
            File.unlink(@body.to_path) rescue nil 
            @body << @body_str
          end
        else
          if (scanner.scan(EmptyLineMatch))
            @chunk_remain = nil
          elsif (scanner.scan(AnyLineMatch))
            raise ParserError::BadRequest
          end
        end
      elsif (scanner.scan(ChunkSizeLineMatch))
        @chunk_remain = scanner[0].to_i(16)
        if (@chunk_remain < 1)
          @state = :body_chunked_tail
        end
      elsif (scanner.scan(AnyLineMatch))
        raise ParserError::BadRequest
      end
    end
def parse_body_chunked ( scanner ) if ( @chunk_remain ) if ( @chunk_remain > 0 ) addition = scanner . string [ scanner . pos , @chunk_remain ] scanner . pos += addition . length @chunk_remain -= addition . length @body_length += addition . length @body << addition if @body if ( @body . length >= @options [ :min_tempfile_size ] && @body . kind_of? ( StringIO ) ) @body_str = @body . string @body = @options [ :tempfile_class ] . new ( "http_parser" ) File . unlink ( @body . to_path ) rescue nil @body << @body_str end else if ( scanner . scan ( EmptyLineMatch ) ) @chunk_remain = nil elsif ( scanner . scan ( AnyLineMatch ) ) raise ParserError :: BadRequest end end elsif ( scanner . scan ( ChunkSizeLineMatch ) ) @chunk_remain = scanner [ 0 ] . to_i ( 16 ) if ( @chunk_remain < 1 ) @state = :body_chunked_tail end elsif ( scanner . scan ( AnyLineMatch ) ) raise ParserError :: BadRequest end end
The HTTP method string used.
The HTTP method string used .
# ruby 1.9.1 does Tempfile.unlink wrong, so we do it ourselves. # the chunk is done. # there was a line with stuff in it, # which is invalid here.
scanner