internal static void ConfigureWebRequest(WebRequest request, IOConnectionInfo ioc) { if (request == null) { Debug.Assert(false); return; } // No throw IocProperties p = ((ioc != null) ? ioc.Properties : null); if (p == null) { Debug.Assert(false); p = new IocProperties(); } IHasIocProperties ihpReq = (request as IHasIocProperties); if (ihpReq != null) { IocProperties pEx = ihpReq.IOConnectionProperties; if (pEx != null) { p.CopyTo(pEx); } else { ihpReq.IOConnectionProperties = p.CloneDeep(); } } if (IsHttpWebRequest(request)) { // WebDAV support #if !KeePassUAP request.PreAuthenticate = true; // Also auth GET #endif if (string.Equals(request.Method, WebRequestMethods.Http.Post, StrUtil.CaseIgnoreCmp)) { request.Method = WebRequestMethods.Http.Put; } #if !KeePassUAP HttpWebRequest hwr = (request as HttpWebRequest); if (hwr != null) { string strUA = p.Get(IocKnownProperties.UserAgent); if (!string.IsNullOrEmpty(strUA)) { hwr.UserAgent = strUA; } } else { Debug.Assert(false); } #endif } #if !KeePassUAP else if (IsFtpWebRequest(request)) { FtpWebRequest fwr = (request as FtpWebRequest); if (fwr != null) { bool?obPassive = p.GetBool(IocKnownProperties.Passive); if (obPassive.HasValue) { fwr.UsePassive = obPassive.Value; } } else { Debug.Assert(false); } } #endif #if !KeePassUAP // Not implemented and ignored in Mono < 2.10 try { request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); } catch (NotImplementedException) { } catch (Exception) { Debug.Assert(false); } #endif try { IWebProxy prx; if (GetWebProxy(out prx)) { request.Proxy = prx; } } catch (Exception) { Debug.Assert(false); } #if !KeePassUAP long?olTimeout = p.GetLong(IocKnownProperties.Timeout); if (olTimeout.HasValue && (olTimeout.Value >= 0)) { request.Timeout = (int)Math.Min(olTimeout.Value, (long)int.MaxValue); } bool?ob = p.GetBool(IocKnownProperties.PreAuth); if (ob.HasValue) { request.PreAuthenticate = ob.Value; } #endif if (IOConnection.IOWebRequestPre != null) { IOWebRequestEventArgs e = new IOWebRequestEventArgs(request, ((ioc != null) ? ioc.CloneDeep() : null)); IOConnection.IOWebRequestPre(null, e); } }