Extra Properties to HtmlWeb

Topics: Developer Forum
Jan 20, 2009 at 7:10 PM
Edited Jan 20, 2009 at 8:06 PM
In our version of HtmlWeb we added a couple Extra Properties:

  private bool _useKeepAlive;
        private int _forcedTimeout;
  /// <summary>
  /// Gets or Sets a value indicating if KeepAlive should be used
  /// Turning off KeepAlive will be less efficient, and connections may have to be re-established,
  /// but it is more reliable, since an open connection is not assumed.
  /// </summary>
  public bool UseKeepAlive
  {
   get
   {
    return _useKeepAlive;
   }
   set
   {
    _useKeepAlive = value;
   }
  }
  /// <summary>
  /// Gets the last request duration in milliseconds.
  /// </summary>
  public int ForcedTimeout
  {
   get
   {
                return _forcedTimeout;
   }
            set
            {
                _forcedTimeout = value;
            }
  }


and changed the code in method HttpStatusCode Get(Uri uri, string method, string path, HtmlDocument doc)

   req = WebRequest.Create(uri) as HttpWebRequest;
            req.Method = method;

to

   req = WebRequest.Create(uri) as HttpWebRequest;
            req.KeepAlive = UseKeepAlive;
            if (ForcedTimeout > 0)
                req.Timeout =ForcedTimeout;
            req.Method = method;
It also will be a good idea to add RequestUserAgent property -see my old post http://thespoke.net/blogs/mnf/archive/2005/05/27/95486.aspx.

If you find them useful, please include the changes to master version.