[Mono-devel-list] small fix

Atsushi Eno atsushi at ximian.com
Tue Mar 29 11:16:53 EST 2005


Hi Kosta,

Yes, I think that is the way it should take. However, AFAIR, there
was an example case that GetEntity() consumed the whole stream up
and after it the network consumption never happened, or example
testcase that requires XmlUrlResolver to implement this way.
Let me find the example.

Atsushi Eno

Konstantin Triger wrote:
> Hello Eno,
> 
> I looked into XmlUrlResolver and found this code:
> 
>        // Methods
>        public override object GetEntity (Uri absoluteUri, string role, 
> Type ofObjectToReturn)
>        {
>            if (ofObjectToReturn == null)
>                ofObjectToReturn = typeof (Stream);
>            if (ofObjectToReturn != typeof (Stream))
>                throw new XmlException ("This object type is not 
> supported.");
> 
>            if (absoluteUri.Scheme == "file") {
>                if (absoluteUri.AbsolutePath == String.Empty)
>                    throw new ArgumentException ("uri must be absolute.", 
> "absoluteUri");
>                return new FileStream (UnescapeRelativeUriBody 
> (absoluteUri.LocalPath), FileMode.Open, FileAccess.Read, FileShare.Read);
>            }
> 
>            // (MS documentation says) parameter role isn't used yet.
>            Stream s = null;
>            using (s) {
>                WebClient wc = new WebClient ();
>                wc.Credentials = credential;
>                byte [] data = wc.DownloadData (absoluteUri.ToString ());
>                wc.Dispose ();
>                return new MemoryStream (data, 0, data.Length);
>             }
>        }
> 
> Don't you think that the highlighted part should be replcaed with that 
> following one (here we return the underlying reponse's stream instead of 
> allocating a new one):
> 
>            WebRequest req = WebRequest.Create(absoluteUri);
>            if (credential != null)
>                req.Credentials = credential;
> 
>            return req.GetResponse().GetResponseStream();
> 




More information about the Mono-devel-list mailing list