public void SetUp()
        {
            _innerRequester = Substitute.For <IHttpRequester>();
            _innerRequester.Request(NotFoundUri, Arg.Any <Options>())
            .Returns(Observable.Throw <Response>(new HttpException(new Uri(""), HttpStatusCode.NotFound)));
            _innerRequester.Request(NotModifiedUri, Arg.Any <Options>())
            .Returns(Observable.Throw <Response>(new HttpException(new Uri(""), HttpStatusCode.NotModified)));

            _httpCache = Substitute.For <IHttpCache>();
            _httpCache.LoadHeaders(Arg.Any <Uri>()).Returns((Dictionary <string, string>)null);

            _fixture = new HttpCacheRequester(_innerRequester, _httpCache);
        }
示例#2
0
        public override IObservable <T> Load <T>(Uri uri, Options options = null)
        {
            if (!Supports <T>(uri))
            {
                throw new NotSupportedException($"Uri not supported: {uri}");
            }

            if (typeof(T) == typeof(Texture2D))
            {
                if (options == null)
                {
                    options = new Options();
                }

                if (options.CustomValues == null)
                {
                    options.CustomValues = new ConcurrentDictionary <object, object>();
                }

                options.CustomValues.Add("TextureRequested", true);
            }

            return(_requester
                   .Request(uri, options)
                   .ContinueWith(x => _converter
                                 .Convert <T>(x.Texture ?? (object)x.Bytes, options?.ContentType ?? x.ContentType, x.Encoding)
                                 .Catch <T, Exception>(ex => Observable
                                                       .Throw <T>(new LoadException("Load failed", ex, uri, options)))));
        }
        private IObservable <Response> LoadFile(Uri uri, Options options, ContentType contentType)
        {
            if (options == null)
            {
                options = new Options();
            }

            options.ContentType = contentType;
            return(_requester.Request(uri, options));
        }
 private void SetupRequest(Uri uri, byte[] bytes, ContentType contentType, string eTag)
 {
     _innerRequester.Request(uri, Arg.Any <Options>())
     .Returns(Observable.Return(
                  new Response(200, () => bytes,
                               new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
     {
         [KnownHttpHeaders.ContentType] = contentType.ToString(),
         [KnownHttpHeaders.ETag]        = eTag
     })));
 }
示例#5
0
        public override IObservable <T> Load <T>(Uri uri, Options options = null)
        {
            if (!Supports <T>(uri))
            {
                throw new NotSupportedException($"Uri not supported: {uri}");
            }

            return(_requester
                   .Request(uri, options)
                   .ContinueWith(x => _converter
                                 .Convert <T>(x.Bytes, options?.ContentType ?? x.ContentType, x.Encoding)
                                 .Catch <T, Exception>(ex => Observable
                                                       .Throw <T>(new LoadException("Load failed", ex, uri, options)))));
        }
示例#6
0
        private IObservable <Response> LoadFile(Uri uri, Options options, string path, ContentType contentType)
        {
            var filePath = System.IO.Path.Combine(Application.streamingAssetsPath, path);

            //   if (filePath.Contains("://"))
            //  {
            if (options == null)
            {
                options = new Options();
            }

            options.ContentType = contentType;
            return(_requester.Request(new Uri(filePath), options));
            //  }

            //   return Observable.Return(System.IO.File.ReadAllBytes(filePath))
            //       .Select(x => new Response(KnownStatusCode.Ok, x, new Dictionary<string, string>()));
        }
        private IObservable <Response> LoadFromOrigin(HttpCachePolicy policy, Uri uri, Options options)
        {
            Log.Debug($"{policy} - Loading resource from origin: {uri}");
            return(_requester
                   .Request(uri, options)
                   .Do(x =>
            {
                if (x.StatusCode == KnownStatusCode.NotModified)
                {
                    throw new HttpException(uri, HttpStatusCode.NotModified);
                }

                if (policy != HttpCachePolicy.OriginOnly)
                {
                    _httpCache.Save(uri, x.Bytes, x.Headers);
                }
            }));
        }
示例#8
0
 public void Request(string url, IDictionary <string, object> data, Encoding encoding, int timeout, HttpRequestCompleteEventHandler onRequestComplete)
 {
     m_Requester.Request(url, data, encoding, timeout, onRequestComplete);
 }