string GetHeaders ()
{
bool continue100 = false;
if (sendChunked) {
continue100 = true;
webHeaders.RemoveAndAdd ("Transfer-Encoding", "chunked");
webHeaders.RemoveInternal ("Content-Length");
} else if (contentLength != -1) {
if (ntlm_auth_state != NtlmAuthState.Challenge) {
if (contentLength > 0)
continue100 = true;
webHeaders.SetInternal ("Content-Length", contentLength.ToString ());
} else {
webHeaders.SetInternal ("Content-Length", "0");
}
webHeaders.RemoveInternal ("Transfer-Encoding");
} else {
webHeaders.RemoveInternal ("Content-Length");
}
if (actualVersion == HttpVersion.Version11 && continue100 &&
servicePoint.SendContinue) { // RFC2616 8.2.3
webHeaders.RemoveAndAdd ("Expect" , "100-continue");
expectContinue = true;
} else {
webHeaders.RemoveInternal ("Expect");
expectContinue = false;
}
bool proxy_query = ProxyQuery;
string connectionHeader = (proxy_query) ? "Proxy-Connection" : "Connection";
webHeaders.RemoveInternal ((!proxy_query) ? "Proxy-Connection" : "Connection");
Version proto_version = servicePoint.ProtocolVersion;
bool spoint10 = (proto_version == null || proto_version == HttpVersion.Version10);
if (keepAlive && (version == HttpVersion.Version10 || spoint10)) {
webHeaders.RemoveAndAdd (connectionHeader, "keep-alive");
} else if (!keepAlive && version == HttpVersion.Version11) {
webHeaders.RemoveAndAdd (connectionHeader, "close");
}
webHeaders.SetInternal ("Host", Host);
if (cookieContainer != null) {
string cookieHeader = cookieContainer.GetCookieHeader (actualUri);
if (cookieHeader != "")
webHeaders.SetInternal ("Cookie", cookieHeader);
}
string accept_encoding = null;
if ((auto_decomp & DecompressionMethods.GZip) != 0)
accept_encoding = "gzip";
if ((auto_decomp & DecompressionMethods.Deflate) != 0)
accept_encoding = accept_encoding != null ? "gzip, deflate" : "deflate";
if (accept_encoding != null)
webHeaders.RemoveAndAdd ("Accept-Encoding", accept_encoding);
if (!usedPreAuth && preAuthenticate)
DoPreAuthenticate ();
return webHeaders.ToString ();
}