public override RequestStatus ProcessRequest(ResourceResponse request, bool prioritized) { try { var httpRequest = WebRequest.CreateHttp(request.Uri); httpRequest.Accept = request.Accept; using (var httpResponse = httpRequest.GetResponse() as HttpWebResponse) { if (httpResponse.StatusCode == HttpStatusCode.NotFound) { return(RequestStatus.NotFound); } if (httpResponse.StatusCode != HttpStatusCode.OK) { return(RequestStatus.ProtocolError); } var resourceStream = new ResourceStream(httpResponse); request.OnResponseStream(resourceStream); return(request.Status); } } catch (Exception exc) { request.Fault = exc; return(RequestStatus.Faulted); } }
public override RequestStatus ProcessRequest(ResourceResponse request, bool prioritized) { var headers = new WebHeaderCollection(); if (!string.IsNullOrWhiteSpace(request.Accept)) { headers.Add(HttpRequestHeader.Accept, request.Accept); } string path = UriToCachePath(request.Uri); if (!File.Exists(path)) { return(RequestStatus.NotFound); } var resourceStream = new ResourceStream(File.OpenRead(path), headers); request.OnResponseStream(resourceStream); return(request.Status); }