예제 #1
0
        private bool Receive()
        {
            CurrentRequest.Response = HTTPProtocolFactory.Get(HTTPProtocolFactory.GetProtocolFromUri(CurrentRequest.CurrentUri), CurrentRequest, Stream, CurrentRequest.UseStreaming, false);

            if (!CurrentRequest.Response.Receive())
            {
                CurrentRequest.Response = null;
                return(false);
            }

            // We didn't check HTTPManager.IsCachingDisabled's value on purpose. (sending out a request with conditional get then change IsCachingDisabled to true may produce undefined behavior)
            if (CurrentRequest.Response.StatusCode == 304)
            {
                int bodyLength;
                using (var cacheStream = HTTPCacheService.GetBody(CurrentRequest.CurrentUri, out bodyLength))
                {
                    if (!CurrentRequest.Response.HasHeader("content-length"))
                    {
                        CurrentRequest.Response.Headers.Add("content-length", new List <string>(1)
                        {
                            bodyLength.ToString()
                        });
                    }
                    CurrentRequest.Response.IsFromCache = true;
                    CurrentRequest.Response.ReadRaw(cacheStream, bodyLength);
                }
            }

            return(true);
        }
 private bool Receive()
 {
     CurrentRequest.Response = HTTPProtocolFactory.Get(HTTPProtocolFactory.GetProtocolFromUri(CurrentRequest.CurrentUri), CurrentRequest, Stream, CurrentRequest.UseStreaming, false);
     if (!CurrentRequest.Response.Receive(-1))
     {
         CurrentRequest.Response = null;
         return(false);
     }
     if (CurrentRequest.Response.StatusCode == 304)
     {
         int length;
         using (Stream stream = HTTPCacheService.GetBody(CurrentRequest.CurrentUri, out length))
         {
             if (!CurrentRequest.Response.HasHeader("content-length"))
             {
                 CurrentRequest.Response.Headers.Add("content-length", new List <string>
                 {
                     length.ToString()
                 });
             }
             CurrentRequest.Response.ReadRaw(stream, length);
         }
     }
     return(true);
 }
예제 #3
0
        private bool LoadFromCache(Uri uri)
        {
            if (HTTPManager.Logger.Level == Logger.Loglevels.All)
            {
                HTTPManager.Logger.Verbose("HTTPConnection", string.Format("{0} - LoadFromCache for Uri: {1}", this.CurrentRequest.CurrentUri.ToString(), uri.ToString()));
            }

            int bodyLength;

            using (var cacheStream = HTTPCacheService.GetBody(uri, out bodyLength))
            {
                if (cacheStream == null)
                {
                    return(false);
                }

                if (!CurrentRequest.Response.HasHeader("content-length"))
                {
                    CurrentRequest.Response.Headers.Add("content-length", new List <string>(1)
                    {
                        bodyLength.ToString()
                    });
                }
                CurrentRequest.Response.IsFromCache = true;
                CurrentRequest.Response.ReadRaw(cacheStream, bodyLength);
            }

            return(true);
        }
예제 #4
0
 private bool Receive()
 {
     this.CurrentRequest.Response = HTTPProtocolFactory.Get(HTTPProtocolFactory.GetProtocolFromUri(this.CurrentRequest.CurrentUri), this.CurrentRequest, this.Stream, this.CurrentRequest.UseStreaming, false);
     if (!this.CurrentRequest.Response.Receive(-1, true))
     {
         this.CurrentRequest.Response = null;
         return(false);
     }
     if (this.CurrentRequest.Response.StatusCode == 304)
     {
         int contentLength;
         using (Stream body = HTTPCacheService.GetBody(this.CurrentRequest.CurrentUri, out contentLength))
         {
             if (!this.CurrentRequest.Response.HasHeader("content-length"))
             {
                 this.CurrentRequest.Response.Headers.Add("content-length", new List <string>(1)
                 {
                     contentLength.ToString()
                 });
             }
             this.CurrentRequest.Response.IsFromCache = true;
             this.CurrentRequest.Response.ReadRaw(body, contentLength);
         }
     }
     return(true);
 }
예제 #5
0
        private bool LoadFromCache(Uri uri)
        {
            int length;

            using (Stream stream = HTTPCacheService.GetBody(uri, out length))
            {
                if (stream == null)
                {
                    return(false);
                }
                if (!base.CurrentRequest.Response.HasHeader("content-length"))
                {
                    base.CurrentRequest.Response.Headers.Add("content-length", new List <string>(1)
                    {
                        length.ToString()
                    });
                }
                base.CurrentRequest.Response.IsFromCache = true;
                base.CurrentRequest.Response.ReadRaw(stream, length);
            }
            return(true);
        }
예제 #6
0
        private bool Receive()
        {
            SupportedProtocols protocol = CurrentRequest.ProtocolHandler == SupportedProtocols.Unknown ? HTTPProtocolFactory.GetProtocolFromUri(CurrentRequest.CurrentUri) : CurrentRequest.ProtocolHandler;

            CurrentRequest.Response = HTTPProtocolFactory.Get(protocol, CurrentRequest, Stream, CurrentRequest.UseStreaming, false);

            if (!CurrentRequest.Response.Receive())
            {
                CurrentRequest.Response = null;
                return(false);
            }

            // We didn't check HTTPManager.IsCachingDisabled's value on purpose. (sending out a request with conditional get then change IsCachingDisabled to true may produce undefined behavior)
            if (CurrentRequest.Response.StatusCode == 304)
            {
#if !BESTHTTP_DISABLE_CACHING && (!UNITY_WEBGL || UNITY_EDITOR)
                int bodyLength;
                using (var cacheStream = HTTPCacheService.GetBody(CurrentRequest.CurrentUri, out bodyLength))
                {
                    if (!CurrentRequest.Response.HasHeader("content-length"))
                    {
                        CurrentRequest.Response.Headers.Add("content-length", new List <string>(1)
                        {
                            bodyLength.ToString()
                        });
                    }
                    CurrentRequest.Response.IsFromCache = true;
                    CurrentRequest.Response.ReadRaw(cacheStream, bodyLength);
                }
#else
                return(false);
#endif
            }

            return(true);
        }