public bool ProcessRequestAsync(IRequest request, ISchemeHandlerResponse response, OnRequestCompletedHandler requestCompletedCallback) { Uri u = new Uri(request.Url); String file = u.Authority; // + u.AbsolutePath; if (File.Exists(file)) { string inZipUri = "index.html"; if (u.AbsolutePath != null) { if (u.AbsolutePath.Substring(0, 1) == "/") { inZipUri = u.AbsolutePath.Substring(1); } } response.ResponseStream = ZipExtractor.ExtractToMemoryStream(u.Authority, inZipUri); switch (Path.GetExtension(inZipUri)) { case ".htm": case ".html": response.MimeType = "text/html"; break; case ".js": response.MimeType = "text/javascript"; break; case ".png": response.MimeType = "image/png"; break; case ".appcache": case ".manifest": response.MimeType = "text/cache-manifest"; break; default: response.MimeType = "application/octet-stream"; break; } requestCompletedCallback(); return(true); } return(false); }
public bool ProcessRequestAsync(IRequest request, ISchemeHandlerResponse response, OnRequestCompletedHandler requestCompletedCallback) { Uri u = new Uri(request.Url); string inZipUri = "index.html"; string zipPath = u.AbsolutePath; int idx = zipPath.IndexOf("::"); if (idx > 0) { inZipUri = zipPath.Substring(idx + 3); zipPath = zipPath.Substring(0, idx); zipPath = zipPath.Replace("%20", " "); } // String file = u.Authority; // + u.AbsolutePath; if (File.Exists(zipPath)) { try { response.ResponseStream = ZipExtractor.ExtractToMemoryStream(zipPath, inZipUri); } catch (Exception exp) { byte[] byteArray = Encoding.ASCII.GetBytes(EncodeHTML( string.Format("Error reading:\n File:'{0}'\n Url:'{1}'\n Message:{2}", zipPath, inZipUri, exp.Message))); MemoryStream stream = new MemoryStream(byteArray); response.ResponseStream = stream; } switch (Path.GetExtension(inZipUri)) { case ".htm": case ".html": response.MimeType = "text/html"; break; case ".js": response.MimeType = "text/javascript"; break; case ".png": response.MimeType = "image/png"; break; case ".appcache": case ".manifest": response.MimeType = "text/cache-manifest"; break; case ".css": response.MimeType = "text/css"; break; default: response.MimeType = "application/octet-stream"; break; } requestCompletedCallback(); return(true); } return(false); }