/// <exception cref="Org.Apache.Http.HttpException"></exception> public override long DetermineLength(HttpMessage message) { Args.NotNull(message, "HTTP message"); Header transferEncodingHeader = message.GetFirstHeader(HTTP.TransferEncoding); // We use Transfer-Encoding if present and ignore Content-Length. // RFC2616, 4.4 item number 3 if (transferEncodingHeader != null) { HeaderElement[] encodings; try { encodings = transferEncodingHeader.GetElements(); } catch (ParseException px) { throw new ProtocolException("Invalid Transfer-Encoding header value: " + transferEncodingHeader , px); } // The chunked encoding must be the last one applied RFC2616, 14.41 int len = encodings.Length; if (Sharpen.Runtime.EqualsIgnoreCase(HTTP.IdentityCoding, transferEncodingHeader. GetValue())) { return Identity; } else { if ((len > 0) && (Sharpen.Runtime.EqualsIgnoreCase(HTTP.ChunkCoding, encodings[len - 1].GetName()))) { return Chunked; } else { return Identity; } } } Header contentLengthHeader = message.GetFirstHeader(HTTP.ContentLen); if (contentLengthHeader != null) { long contentlen = -1; Header[] headers = message.GetHeaders(HTTP.ContentLen); for (int i = headers.Length - 1; i >= 0; i--) { Header header = headers[i]; try { contentlen = long.Parse(header.GetValue()); break; } catch (FormatException) { } } // See if we can have better luck with another header, if present if (contentlen >= 0) { return contentlen; } else { return Identity; } } return this.implicitLen; }