From: matz@... (Yukihiro Matsumoto) Date: 2003-07-24T01:21:54+09:00 Subject: [ruby-list:37965] Re: multipart/form-dataのためのcgi.rbの修正 まつもと ゆきひろです In message "[ruby-list:37964] Re: multipart/form-dataのためのcgi.rbの修正" on 03/07/24, Yukihiro Matsumoto writes: |tempfileのこともあるのでちょっと考える必要がありますが、基本 |的な要望は理解しました。 こんな感じでどうでしょう? ちゃんと期待通り動きますか? --- lib/cgi.rb 2 Jun 2003 04:49:46 -0000 1.52 +++ lib/cgi.rb 23 Jul 2003 16:21:03 -0000 @@ -802,3 +802,3 @@ convert string charset, and set language begin - require "stringio" if not defined? StringIO + require "stringio" body = StringIO.new @@ -919,2 +919,3 @@ convert string charset, and set language boundary = $1.dup + @multipart = true @params = read_multipart(boundary, Integer(env_table['CONTENT_LENGTH'])) @@ -949,3 +950,2 @@ convert string charset, and set language def [](idx) - p caller(1) warn "#{caller(1)[0]}:CAUTION! cgi['key'] == cgi.params['key'][0]; if want Array, use cgi.params['key']" @@ -966,4 +966,13 @@ convert string charset, and set language value = params[0] - value ||= "" - Value.new(value,params) + if @multipart + if value + return value + elsif defined? StringIO + StringIO.new("") + else + Tempfile.new("CGI") + end + else + Value.new(value || "", params) + end end @@ -1933,2 +1942,3 @@ The hash keys are case sensitive. Ask th extend QueryExtension + @multipart = false if "POST" != env_table['REQUEST_METHOD']