2
對於流式http端點有沒有辦法避免發送長度?如何避免發送內容長度標頭
w.Header().Set("Content-Type", "image/jpeg")
w.Header().Set("Transfer-Encoding", "chunked")
w.Header().Del("Content-Length")
這就是我回來的。
HTTP/1.1 200 OK
Content-Length: 0
Content-Type: image/jpeg
Date: Mon, 23 Jun 2014 10:00:59 GMT
Transfer-Encoding: chunked
Transfer-Encoding: chunked
服務器也會輸出警告。
2014/06/23 06:04:03 http: WriteHeader called with both Transfer-Encoding of "chunked" and a Content-Length of 0
剛纔注意到在你的例子中的雙重Transfert編碼。只要刪除設置'transfert-encoding'和'content-length',它應該工作得很好:) – creack
澄清:一旦你調用ResponseWriter的WriteHeader,net/http將默認發送'Transfer-Encoding:chunked'或寫入方法;如果您希望處理程序發送的響應中包含Content-Length,則必須自行設置標題。 – krait