Using UTF-8 realm in HTTP Basic access authentication

user-pic
Vote 0 Votes

If you are looking for solution, I found it's not possible to use UTF-8 realm in HTTP Basic access authentication.

在 UTF-8 環境下, 使用 Apache + 下面的 .htaccess, 用瀏覽器看, 在登入畫面會看到亂碼
AuthName 中文測試
AuthType Basic
AuthUserFile .htpasswd
require valid-user

查了 Server 端送出的 Header, WWW-Authenticate: Basic realm="中文測試", 是正常沒有編碼的
但是 charset 錯誤, Content-Type: text/html; charset=iso-8859-1
即使有加 AddDefaultCharset UTF-8, Apache 在認證畫面仍是送出 charset=iso-8859-1
原本我以為這是問題的原因, 於是我修改了 Apache source modules/mappers/mod_negotiation.c
把 default charset iso-8859-1 改成 UTF-8, 重編之後,
認證畫面已送出 Content-Type: text/html; charset=UTF-8,
但是瀏覽器(Firefox, Chrome, Opera, IE)看到的一樣是亂碼, 表示瀏覽器在認證畫面根本不看 charset
又去查 RFC 2617, 也沒有提到跟 charset 有關的東西
瀏覽器在認證畫面根本不看 charset 的話, 就是看瀏覽器預設處理方式
經測試,
Firefox, Chrome, Opera 是用 iso-8859-1 (英語/西歐語系)
中文版 IE 是用 Big5, 在 AuthName 使用 Big5 編碼用 IE 看是唯一可以看到正常字元的組合
結論是在 HTTP 基本認證使用 UTF-8 realm 是不可行的

About this Entry

This page contains a single entry by Pank published on August 6, 2014 10:56 AM.

Windows 32bit and 64bit Registry was the previous entry in this blog.

Non-Taiwan IPv4 Addresses is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Monthly Archives