http content-length 回錯會造成 chrome 顯示白畫面

剛好在 porting 一個 open source http server,發現如果 content-length 回錯值,比 content 大小還大時,chrome 顯示白畫面


看 chrome 的 request header 會變成:


GET /index.html HTTP/1.1
Host: 172.16.196.15:8080
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36
Accept-Encoding: gzip,deflate,sdch
Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
Range: 26-26


而 server 的 response header 是:


HTTP/1.1 200 OK
Server: myhttp
Date: Wed Jan 26 20:15:02 2000
Content-Length: 530524
Connection: keep-alive
Content-Type: text/html
Last-Modified: Sat Jan 03 06:10:52 1970


事實上 content length 是 26 bytes 才對。我猜想因為 header 回錯,當 server 資料 send 出 26 bytes 後,server 結束傳送,但 chrome 這邊還在痴痴的等?原因其實並不是那麼清楚。


不過後來給對的 content-length 後,chrome 就可以正常看到結果了。


留言

熱門文章