int maxResponseHeadersLength;
static int defaultMaxResponseHeadersLength;
int readWriteTimeout = 300000; // ms
- IMonoTlsProvider tlsProvider;
#if SECURITY_DEP
+ MonoTlsProvider tlsProvider;
MonoTlsSettings tlsSettings;
#endif
ServerCertValidationCallback certValidationCallback;
static HttpWebRequest ()
{
defaultMaxResponseHeadersLength = 64 * 1024;
-#if !NET_2_1
+#if !MOBILE
+#pragma warning disable 618
NetConfig config = ConfigurationSettings.GetConfig ("system.net/settings") as NetConfig;
+#pragma warning restore 618
if (config != null) {
int x = config.MaxResponseHeadersLength;
if (x != -1)
#endif
}
-#if NET_2_1
+#if MOBILE
public
#else
internal
{
this.requestUri = uri;
this.actualUri = uri;
- this.proxy = GlobalProxySelection.Select;
- this.webHeaders = new WebHeaderCollection (WebHeaderCollection.HeaderInfo.Request);
+ this.proxy = InternalDefaultWebProxy;
+ this.webHeaders = new WebHeaderCollection (WebHeaderCollectionType.HttpWebRequest);
ThrowOnError = true;
ResetAuthorization ();
}
#if SECURITY_DEP
- internal HttpWebRequest (Uri uri, IMonoTlsProvider tlsProvider, MonoTlsSettings settings = null)
+ internal HttpWebRequest (Uri uri, MonoTlsProvider tlsProvider, MonoTlsSettings settings = null)
: this (uri)
{
this.tlsProvider = tlsProvider;
// Properties
+ void SetSpecialHeaders(string HeaderName, string value) {
+ value = WebHeaderCollection.CheckBadChars(value, true);
+ webHeaders.RemoveInternal(HeaderName);
+ if (value.Length != 0) {
+ webHeaders.AddInternal(HeaderName, value);
+ }
+ }
+
public string Accept {
get { return webHeaders ["Accept"]; }
set {
CheckRequestStarted ();
- webHeaders.RemoveAndAdd ("Accept", value);
+ SetSpecialHeaders ("Accept", value);
}
}
internal set { actualUri = value; } // Used by Ftp+proxy
}
- public bool AllowAutoRedirect {
+ public virtual bool AllowAutoRedirect {
get { return allowAutoRedirect; }
set { this.allowAutoRedirect = value; }
}
- public bool AllowWriteStreamBuffering {
+ public virtual bool AllowWriteStreamBuffering {
get { return allowBuffering; }
set { allowBuffering = value; }
}
}
}
- internal IMonoTlsProvider TlsProvider {
+#if SECURITY_DEP
+ internal MonoTlsProvider TlsProvider {
get { return tlsProvider; }
}
-#if SECURITY_DEP
internal MonoTlsSettings TlsSettings {
get { return tlsSettings; }
}
#endif
-
+
public X509CertificateCollection ClientCertificates {
get {
if (certificates == null)
if (keepAlive)
value = value + ", Keep-Alive";
- webHeaders.RemoveAndAdd ("Connection", value);
+ webHeaders.CheckUpdate ("Connection", value);
}
}
public override string ContentType {
get { return webHeaders ["Content-Type"]; }
set {
- if (value == null || value.Trim().Length == 0) {
- webHeaders.RemoveInternal ("Content-Type");
- return;
- }
- webHeaders.RemoveAndAdd ("Content-Type", value);
+ SetSpecialHeaders ("Content-Type", value);
}
}
return DateTime.ParseExact (date, "r", CultureInfo.InvariantCulture).ToLocalTime ();
}
set {
- if (value.Equals (DateTime.MinValue))
- webHeaders.RemoveInternal ("Date");
- else
- webHeaders.RemoveAndAdd ("Date", value.ToUniversalTime ().ToString ("r", CultureInfo.InvariantCulture));
+ SetDateHeaderHelper ("Date", value);
}
}
-#if !NET_2_1
+ void SetDateHeaderHelper(string headerName, DateTime dateTime) {
+ if (dateTime == DateTime.MinValue)
+ SetSpecialHeaders(headerName, null); // remove header
+ else
+ SetSpecialHeaders(headerName, HttpProtocolUtils.date2string(dateTime));
+ }
+
+#if !MOBILE
[MonoTODO]
public static new RequestCachePolicy DefaultCachePolicy
{
if (val == "100-continue")
throw new ArgumentException ("100-Continue cannot be set with this property.",
"value");
- webHeaders.RemoveAndAdd ("Expect", value);
+
+ webHeaders.CheckUpdate ("Expect", value);
}
}
get { return webHeaders; }
set {
CheckRequestStarted ();
- WebHeaderCollection newHeaders = new WebHeaderCollection (WebHeaderCollection.HeaderInfo.Request);
- int count = value.Count;
- for (int i = 0; i < count; i++)
- newHeaders.Add (value.GetKey (i), value.Get (i));
- webHeaders = newHeaders;
+ WebHeaderCollection webHeaders = value;
+ WebHeaderCollection newWebHeaders = new WebHeaderCollection(WebHeaderCollectionType.HttpWebRequest);
+
+ // Copy And Validate -
+ // Handle the case where their object tries to change
+ // name, value pairs after they call set, so therefore,
+ // we need to clone their headers.
+ //
+
+ foreach (String headerName in webHeaders.AllKeys ) {
+ newWebHeaders.Add(headerName,webHeaders[headerName]);
+ }
+
+ this.webHeaders = newWebHeaders;
}
}
if (!sendChunked)
throw new ArgumentException ("SendChunked must be True", "value");
- webHeaders.RemoveAndAdd ("Transfer-Encoding", value);
+ webHeaders.CheckUpdate ("Transfer-Encoding", value);
}
}
{
if (rangeSpecifier == null)
throw new ArgumentNullException ("rangeSpecifier");
- if (!WebHeaderCollection.IsHeaderValue (rangeSpecifier))
+ if (!WebHeaderCollection.IsValidToken (rangeSpecifier))
throw new ArgumentException ("Invalid range specifier", "rangeSpecifier");
string r = webHeaders ["Range"];
r = r + "0" + n;
else
r = r + n + "-";
- webHeaders.RemoveAndAdd ("Range", r);
+ webHeaders.ChangeInternal ("Range", r);
}
public
{
if (rangeSpecifier == null)
throw new ArgumentNullException ("rangeSpecifier");
- if (!WebHeaderCollection.IsHeaderValue (rangeSpecifier))
+ if (!WebHeaderCollection.IsValidToken (rangeSpecifier))
throw new ArgumentException ("Invalid range specifier", "rangeSpecifier");
if (from > to || from < 0)
throw new ArgumentOutOfRangeException ("from");
r += ",";
r = String.Format ("{0}{1}-{2}", r, from, to);
- webHeaders.RemoveAndAdd ("Range", r);
+ webHeaders.ChangeInternal ("Range", r);
}
return EndGetRequestStream (asyncResult);
}
+ [MonoTODO]
+ public Stream GetRequestStream (out TransportContext context)
+ {
+ throw new NotImplementedException ();
+ }
+
bool CheckIfForceWrite (SimpleAsyncResult result)
{
if (writeStream == null || writeStream.RequestWritten || !InternalAllowBuffering)
initialMethod = method;
SimpleAsyncResult.RunWithLock (locker, CheckIfForceWrite, inner => {
- var synch = inner.CompletedSynchronously;
+ var synch = inner.CompletedSynchronouslyPeek;
if (inner.GotException) {
aread.SetCompleted (synch, inner.Exception);
return result.Response;
}
- public Stream EndGetRequestStream (IAsyncResult asyncResult, out TransportContext transportContext)
+ public Stream EndGetRequestStream (IAsyncResult asyncResult, out TransportContext context)
{
- transportContext = null;
+ context = null;
return EndGetRequestStream (asyncResult);
}
bool continue100 = false;
if (sendChunked) {
continue100 = true;
- webHeaders.RemoveAndAdd ("Transfer-Encoding", "chunked");
+ webHeaders.ChangeInternal ("Transfer-Encoding", "chunked");
webHeaders.RemoveInternal ("Content-Length");
} else if (contentLength != -1) {
if (auth_state.NtlmAuthState == NtlmAuthState.Challenge || proxy_auth_state.NtlmAuthState == NtlmAuthState.Challenge) {
if (actualVersion == HttpVersion.Version11 && continue100 &&
servicePoint.SendContinue) { // RFC2616 8.2.3
- webHeaders.RemoveAndAdd ("Expect" , "100-continue");
+ webHeaders.ChangeInternal ("Expect" , "100-continue");
expectContinue = true;
} else {
webHeaders.RemoveInternal ("Expect");
if (keepAlive && (version == HttpVersion.Version10 || spoint10)) {
if (webHeaders[connectionHeader] == null
|| webHeaders[connectionHeader].IndexOf ("keep-alive", StringComparison.OrdinalIgnoreCase) == -1)
- webHeaders.RemoveAndAdd (connectionHeader, "keep-alive");
+ webHeaders.ChangeInternal (connectionHeader, "keep-alive");
} else if (!keepAlive && version == HttpVersion.Version11) {
- webHeaders.RemoveAndAdd (connectionHeader, "close");
+ webHeaders.ChangeInternal (connectionHeader, "close");
}
webHeaders.SetInternal ("Host", Host);
if (cookieContainer != null) {
string cookieHeader = cookieContainer.GetCookieHeader (actualUri);
if (cookieHeader != "")
- webHeaders.RemoveAndAdd ("Cookie", cookieHeader);
+ webHeaders.ChangeInternal ("Cookie", cookieHeader);
else
webHeaders.RemoveInternal ("Cookie");
}
if ((auto_decomp & DecompressionMethods.Deflate) != 0)
accept_encoding = accept_encoding != null ? "gzip, deflate" : "deflate";
if (accept_encoding != null)
- webHeaders.RemoveAndAdd ("Accept-Encoding", accept_encoding);
+ webHeaders.ChangeInternal ("Accept-Encoding", accept_encoding);
if (!usedPreAuth && preAuthenticate)
DoPreAuthenticate ();
msg = "Error: " + status;
wex = new WebException (msg, status);
} else {
- msg = String.Format ("Error: {0} ({1})", status, exc.Message);
- wex = new WebException (msg, status, WebExceptionInternalStatus.RequestFatal, exc);
+ wex = exc as WebException;
+ if (wex == null) {
+ msg = String.Format ("Error: {0} ({1})", status, exc.Message);
+ wex = new WebException (msg, status, WebExceptionInternalStatus.RequestFatal, exc);
+ }
}
r.SetCompleted (false, wex);
r.DoCallback ();
}
if (asyncWrite != null) {
- asyncWrite.SetCompleted (inner.CompletedSynchronously, writeStream);
+ asyncWrite.SetCompleted (inner.CompletedSynchronouslyPeek, writeStream);
asyncWrite.DoCallback ();
asyncWrite = null;
}
if (wce != null) {
WebConnection cnc = wce.Connection;
cnc.PriorityRequest = this;
- ICredentials creds = !isProxy ? credentials : proxy.Credentials;
+ ICredentials creds = (!isProxy || proxy == null) ? credentials : proxy.Credentials;
if (creds != null) {
cnc.NtlmCredential = creds.GetCredential (requestUri, "NTLM");
cnc.UnsafeAuthenticatedConnectionSharing = unsafe_auth_blah;
return;
}
- bool isProxy = ProxyQuery && !proxy.IsBypassed (actualUri);
+ bool isProxy = ProxyQuery && proxy != null && !proxy.IsBypassed (actualUri);
bool redirected;
try {
if (isProxy && (request.proxy == null || request.proxy.Credentials == null))
return false;
- string [] authHeaders = response.Headers.GetValues_internal (isProxy ? "Proxy-Authenticate" : "WWW-Authenticate", false);
+ string [] authHeaders = response.Headers.GetValues (isProxy ? "Proxy-Authenticate" : "WWW-Authenticate");
if (authHeaders == null || authHeaders.Length == 0)
return false;
}
internal WebConnection StoredConnection;
+
+#region referencesource
+ internal static StringBuilder GenerateConnectionGroup(string connectionGroupName, bool unsafeConnectionGroup, bool isInternalGroup)
+ {
+ StringBuilder connectionLine = new StringBuilder(connectionGroupName);
+
+ connectionLine.Append(unsafeConnectionGroup ? "U>" : "S>");
+
+ if (isInternalGroup)
+ {
+ connectionLine.Append("I>");
+ }
+
+ return connectionLine;
+ }
+#endregion
}
}