Gaucheのhttp-postとrequest-encoding
またまた、http-postのこと。
第3引き数のbodyを、リストタイプで指定して、例えばeuc-jpで送りたい。
このケースでも、bodyそのものの文字コードは自前で変換なのかな、という話。
例えば、以下のようなソースだと、request-encodingにeuc-jpを指定しても、データ本体は、どうもutf-8のままっぽい。
っぽい、というのもsjis-cygwin上でutf8-gaucheを動かしているからなんかどうかなってるのかも、という気もするので。
(gauche-character-encoding)はutf-8。
ソースファイルの文字コードはutf-8。
(use rfc.http) (define svr "127.0.0.1") (guard (excp ((condition-has-type? excp <http-error>) (format #t "connection error~%") 'http-error) ;(else (format #t "what's happen?") 'other-error) ) (receive (status header body) (http-post svr "/gauche/post.cgi" '(("str" "日本語そのまま")("str2" "日本語そのまま2")) :request-encoding "euc-jp" ) (display body)))
送信データ全体のヘッダを見ると、content-typeはmultipart/form-dataになっており、リストタイプの引き数として変換はされている。
そこで、おそらく内部的にもhttp-compose-form-dataを使っているだろうから、
(call-with-output-file "test.txt" (lambda (p) (http-compose-form-data '(("str" "日本語そのまま")) p "euc-jp")))
みたいなスクリプトを書いて出力を見てみる。
すると、
--boundary-6p2rdh0ilogfln586q08w Content-type: text/plain; charset=euc-jp Content-transfer-encoding: binary content-disposition: form-data; name=str 日本語そのまま --boundary-6p2rdh0ilogfln586q08w--
という内容がutf-8で出力される。
euc-jpだよ、という印は付けるから、データそのものは自前で変換、という理解でいいんだろうか。