> @headers["Content-Type"] = "text/html; charset=Shift_JIS"
This sets the http content type header to indicate the character set the page uses for the browser: it reflects what you see (in firefox) when you look at the Tools > Page Info > Encoding. In my experience putting the character set in the page doesn't work if there is a character set declared in one of the http headers.