/// <summary> /// reset ContentLength with the accurate value /// </summary> public void SetAutoContentLength() { if (ResponseHeads == null) { ResponseHeads = new List <MyKeyValuePair <string, string> >(); } else { List <MyKeyValuePair <string, string> > mvKvpList = new List <MyKeyValuePair <string, string> >(); foreach (MyKeyValuePair <string, string> kvp in ResponseHeads) { if (kvp.Key.ToLower() == "content-length") { mvKvpList.Add(kvp); } } if (mvKvpList.Count > 0) { foreach (MyKeyValuePair <string, string> kvp in mvKvpList) { ResponseHeads.Remove(kvp); } } } ResponseHeads.Add(new MyKeyValuePair <string, string>("Content-Length", ResponseEntity == null ? "0" : ResponseEntity.Length.ToString())); }
/// <summary> /// reset ContentLength with the accurate value /// </summary> public void SetAutoContentLength() { if (ResponseHeads == null) { ResponseHeads = new List <MyKeyValuePair <string, string> >(); } else { /* * List<MyKeyValuePair<string, string>> mvKvpList = new List<MyKeyValuePair<string, string>>(); * foreach (MyKeyValuePair<string, string> kvp in ResponseHeads) * { * if (kvp.Key.ToLower() == "content-length") * { * mvKvpList.Add(kvp); * } * } * if (mvKvpList.Count > 0) * { * foreach (MyKeyValuePair<string, string> kvp in mvKvpList) * { * ResponseHeads.Remove(kvp); * } * } * **/ int responseHeadsCount = ResponseHeads.Count; for (int i = responseHeadsCount - 1; i >= 0; i--) { if (ResponseHeads[i].Key.ToLower() == "content-length") { ResponseHeads.RemoveAt(i); } } } if (ResponseEntity == null || ResponseEntity.Length == 0) { return; } ResponseHeads.Add(new MyKeyValuePair <string, string>("Content-Length", ResponseEntity == null ? "0" : ResponseEntity.Length.ToString())); }