public void it_should_follow_redirects() { var service = new Mock<IRemoteResourceService>(); var dispatcher = new Mock<IRequestDispatcher>(); var chain = new ResponseChain(service.Object, new IResponseFeature[0]); var response = TestHelper.CreateResponse(HttpStatusCode.Created, new Dictionary<string, string> { { "Location", "file://NotImportant" } }); service.SetupGet(s => s.Dispatcher).Returns(dispatcher.Object); new FollowRedirects().Process(chain, response); dispatcher.Verify(d => d.Process(service.Object, It.IsAny<string>(), It.IsAny<Uri>(), It.IsAny<string>())); }
public void it_should_auto_refresh() { var service = new Mock<IRemoteResourceService>(); var dispatcher = new Mock<IRequestDispatcher>(); var chain = new ResponseChain(service.Object, new IResponseFeature[0]); var response = TestHelper.CreateResponse(headers: new Dictionary<string, string> { { "Refresh", "5; url=http://NotImportant" } }); service.SetupGet(s => s.IsAsynch).Returns(true); service.SetupGet(s => s.Dispatcher).Returns(dispatcher.Object); new AutoRefresh().Process(chain, response); dispatcher.Verify(d => d.Process(service.Object, It.IsAny<string>(), It.IsAny<Uri>(), It.IsAny<string>())); }
public HttpRemoteResponse Process(ResponseChain chain, HttpRemoteResponse response) { response = chain.Next(response); if (!ShouldRedirect(response)) return response; string uri; if (response.Headers.TryGetValue("Location", out uri) && !String.IsNullOrWhiteSpace(uri)) { chain.Reset(); response = chain.Service.Dispatcher.Process(chain.Service, "GET", new Uri(uri), null); response = chain.Next(response); } return response; }
public HttpRemoteResponse Process(ResponseChain chain, HttpRemoteResponse response) { if (!chain.Service.IsAsynch) throw new NotSupportedException("AutoRefresh is not supported on synchronous requests"); response = chain.Next(response); Refresh refresh; if (!ShouldRefresh(response, out refresh) || refresh == null) return response; Thread.Sleep(TimeSpan.FromSeconds(refresh.Seconds)); // TODO: use a better alternative response = chain.Service.Dispatcher.Process(chain.Service, "GET", new Uri(refresh.Uri), null); response = chain.Next(response); return response; }