public bool ProcessRequestAsync(IRequest request, ISchemeHandlerResponse response, OnRequestCompletedHandler requestCompletedCallback) { var u = new Uri(request.Url); var file = u.Authority + u.AbsolutePath; var assembly = Assembly.GetExecutingAssembly(); var resourcePath = assembly.GetName().Name + "." + file.Replace("/", "."); if (assembly.GetManifestResourceInfo(resourcePath) == null) return false; response.ResponseStream = assembly.GetManifestResourceStream(resourcePath); switch (Path.GetExtension(file)) { 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; }
public bool ProcessRequestAsync(IRequest request, ISchemeHandlerResponse response, OnRequestCompletedHandler requestCompletedCallback) { var uri = new Uri(request.Url); var fileName = string.Format("{0}{1}", uri.Authority, uri.AbsolutePath); if (fileName[fileName.Length - 1] == '/') fileName = fileName.Substring(0, fileName.Length - 1); if (File.Exists(fileName)) { var fileBytes = File.ReadAllBytes(fileName); response.ResponseStream = new MemoryStream(fileBytes); switch (Path.GetExtension(fileName)) { case ".html": response.MimeType = "text/html"; break; case ".js": response.MimeType = "text/javascript"; break; case ".css": response.MimeType = "text/css"; 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 file = u.Authority + u.AbsolutePath; if(File.Exists(file)) { Byte[] bytes = File.ReadAllBytes(file); response.ResponseStream = new MemoryStream(bytes); switch(Path.GetExtension(file)) { 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) { IDictionary <string, string[]> requestHeaders = request.Headers.ToDictionary(); Stream requestBody = Stream.Null; if (request.Body != null) { byte[] bytes = Encoding.UTF8.GetBytes(request.Body); requestBody = new MemoryStream(bytes, 0, bytes.Length); } var uri = new Uri(request.Url); var environment = new Dictionary <string, object> { { "owin.RequestBody", requestBody }, { "owin.RequestHeaders", requestHeaders }, { "owin.RequestMethod", request.Method }, { "owin.RequestPath", uri.AbsolutePath }, { "owin.RequestPathBase", "/" }, { "owin.RequestProtocol", "HTTP/1.1" }, { "owin.RequestQueryString", uri.Query }, { "owin.RequestScheme", "HTTP/1.1" }, { "owin.ResponseHeaders", new Dictionary <string, string[]>() }, }; var stream = new ResponseStream(() => { string status = "200 OK"; if (environment.ContainsKey("owin.ResponseStatusCode")) { var statusCode = environment["owin.ResponseStatusCode"].ToString(); status = environment.ContainsKey("owin.ResponseReasonPhrase") ? statusCode + " " + environment["owin.ResponseReasonPhrase"].ToString() : statusCode + " " + ReasonPhrases[int.Parse(environment["owin.ResponseStatusCode"].ToString())]; } //TODO CefSharp seems to be ignoring the status code and turning it to a 200OK :| response.ResponseHeaders = new NameValueCollection { { "Status Code", status } }; var responseHeaders = (Dictionary <string, string[]>)environment["owin.ResponseHeaders"]; foreach (KeyValuePair <string, string[]> responseHeader in responseHeaders) { response.ResponseHeaders.Add(responseHeader.Key, string.Join(";", responseHeader.Value)); } response.MimeType = !response.ResponseHeaders.AllKeys.Contains("Content-Type") ? "text/plain" : response.ResponseHeaders["Content-Type"]; }); response.ResponseStream = stream; environment.Add("owin.ResponseBody", stream); _appFunc.Invoke(environment).ContinueWith(task => requestCompletedCallback()); return(true); }
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) { if (AssetProvider.IsLocal(request.Url)) { AssetResource asset = AssetProvider.Get(request.Url); response.MimeType = asset.MimeType; response.ResponseStream = asset.Resource; requestCompletedCallback.Invoke(); return(true); } return(false); }
public bool ProcessRequestAsync(IRequest request, ISchemeHandlerResponse response, OnRequestCompletedHandler requestCompletedCallback) { if (request.Url.StartsWith(internalDomain)) { var httpRequestMessage = httpConverter.ToOwinHttpRequest(request); GetResponse(httpRequestMessage).ContinueWith(requestTask => { Respond(response, requestTask.Result); requestCompletedCallback(); }); return(true); } return(false); }
public bool ProcessRequestAsync(IRequest request, ISchemeHandlerResponse response, OnRequestCompletedHandler requestCompletedCallback) { Uri u = new Uri(request.Url); String file = u.Authority + u.AbsolutePath; Assembly ass = Assembly.GetExecutingAssembly(); String resourcePath = ass.GetName().Name + "." + file.Replace("/", "."); if (ass.GetManifestResourceInfo(resourcePath) != null) { response.ResponseStream = ass.GetManifestResourceStream(resourcePath); switch (Path.GetExtension(file)) { 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) { var uri = new Uri(request.Url); var segments = uri.Segments; var path = Path.Combine(HtmlPreview.BaseDirectory, string.Concat(uri.Segments.Skip(1).Select(p => p.Replace("/", "\\")))); var file = new FileInfo(path); if (file.Exists) { response.ResponseStream = file.OpenRead(); response.MimeType = "text/html"; return true; } return false; }
public bool ProcessRequestAsync(IRequest request, ISchemeHandlerResponse response, OnRequestCompletedHandler requestCompletedCallback) { if (request.Method == "GET") { Uri uri = new Uri(request.Url); string filePath = dataPath + uri.AbsolutePath.Replace("/", @"\"); if (uri.Authority == "timeline" && File.Exists(filePath)) { Byte[] bytes = File.ReadAllBytes(filePath); response.ResponseStream = new MemoryStream(bytes); switch (Path.GetExtension(filePath)) { case ".html": response.MimeType = "text/html"; break; case ".css": response.MimeType = "text/css"; break; case ".js": response.MimeType = "text/javascript"; break; case ".png": response.MimeType = "image/png"; break; default: response.MimeType = "application/octet-stream"; break; } requestCompletedCallback(); return true; } return false; } else { return false; } }
public bool ProcessRequestAsync(IRequest request, SchemeHandlerResponse response, OnRequestCompletedHandler requestCompletedCallback) { // The 'host' portion is entirely ignored by this scheme handler. var uri = new Uri(request.Url); var fileName = uri.AbsolutePath; string resource; if (resources.TryGetValue(fileName, out resource) && !String.IsNullOrEmpty(resource)) { var bytes = Encoding.UTF8.GetBytes(resource); response.ResponseStream = new MemoryStream(bytes); response.MimeType = GetMimeType(fileName); requestCompletedCallback(); return true; } return false; }
public bool ProcessRequestAsync(IRequest request, ISchemeHandlerResponse response, OnRequestCompletedHandler requestCompletedCallback) { var uri = new Uri(request.Url); var file = uri.Authority + uri.AbsolutePath; file = file.Replace("/", ""); if(File.Exists(file)) { var bytes = File.ReadAllBytes(file); response.ResponseStream = new MemoryStream(bytes); switch(Path.GetExtension(file)) { case ".html": response.MimeType = "text/html"; break; } requestCompletedCallback(); return true; } return false; }
public bool ProcessRequestAsync(IRequest request, ISchemeHandlerResponse response, OnRequestCompletedHandler requestCompletedCallback) { //gapp:// ignore this // The 'host' portion is entirely ignored by this scheme handler. try { var uri = new Uri(request.Url); var fileName = uri.ToString().Substring(7).Replace('/', '\\').Insert(1, ":"); if (System.IO.File.Exists(fileName)) { response.ResponseStream = System.IO.File.OpenRead(fileName); response.MimeType = GetMimeType(fileName); requestCompletedCallback.BeginInvoke(requestCompletedCallback.EndInvoke, null); return true; } } catch { } return false; }
public bool ProcessRequestAsync(IRequest request, ISchemeHandlerResponse response, OnRequestCompletedHandler requestCompletedCallback) { // The 'host' portion is entirely ignored by this scheme handler. var uri = new Uri(request.Url); var fileName = uri.AbsolutePath; string resource; if (resources.TryGetValue(fileName, out resource) && !String.IsNullOrEmpty(resource)) { var bytes = Encoding.UTF8.GetBytes(resource); response.ResponseStream = new MemoryStream(bytes); response.MimeType = GetMimeType(fileName); //Execute in async fashion requestCompletedCallback.BeginInvoke(requestCompletedCallback.EndInvoke, null); return(true); } return(false); }
public bool ProcessRequestAsync(IRequest request, ISchemeHandlerResponse response, OnRequestCompletedHandler requestCompletedCallback) { if (request.Method == "GET") { Uri uri = new Uri(request.Url); string filePath = dataPath + uri.AbsolutePath.Replace("/", @"\"); if (uri.Authority == "timeline" && File.Exists(filePath)) { Byte[] bytes = File.ReadAllBytes(filePath); response.ResponseStream = new MemoryStream(bytes); switch (Path.GetExtension(filePath)) { case ".html": response.MimeType = "text/html"; break; case ".css": response.MimeType = "text/css"; break; case ".js": response.MimeType = "text/javascript"; break; case ".png": response.MimeType = "image/png"; break; default: response.MimeType = "application/octet-stream"; break; } requestCompletedCallback(); return(true); } return(false); } else { return(false); } }
public bool ProcessRequestAsync(IRequest request, ISchemeHandlerResponse response, OnRequestCompletedHandler requestCompletedCallback) { var uri = new Uri(request.Url); var segments = uri.Segments; var path = Path.Combine(HtmlPreview.BaseDirectory, string.Concat(uri.Segments.Skip(1).Select(p => p.Replace('/', '\\')))); var file = new FileInfo(path); if (file.Exists) { response.ResponseStream = file.OpenRead(); response.MimeType = "text/html"; return(true); } return(false); }
public bool ProcessRequestAsync(IRequest request, ISchemeHandlerResponse response, OnRequestCompletedHandler requestCompletedCallback) { var uri = new Uri(request.Url); var fileName = string.Format("{0}{1}", uri.Authority, uri.AbsolutePath); if (fileName[fileName.Length - 1] == '/') { fileName = fileName.Substring(0, fileName.Length - 1); } if (File.Exists(fileName)) { var fileBytes = File.ReadAllBytes(fileName); response.ResponseStream = new MemoryStream(fileBytes); switch (Path.GetExtension(fileName)) { case ".html": response.MimeType = "text/html"; break; case ".js": response.MimeType = "text/javascript"; break; case ".css": response.MimeType = "text/css"; 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 file = u.Authority + u.AbsolutePath; if (File.Exists(file)) { Byte[] bytes = File.ReadAllBytes(file); response.ResponseStream = new MemoryStream(bytes); switch (Path.GetExtension(file)) { 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); }
public bool ProcessRequestAsync(IRequest request, SchemeHandlerResponse response, OnRequestCompletedHandler requestCompletedCallback) { var uri = new Uri(request.Url); var segments = uri.Segments; var file = segments[segments.Length - 1]; string resource; if (resources.TryGetValue(file, out resource) && !String.IsNullOrEmpty(resource)) { var bytes = Encoding.UTF8.GetBytes(resource); response.ResponseStream = new MemoryStream(bytes); response.MimeType = "text/html"; requestCompletedCallback(); return(true); } return(false); }
public bool ProcessRequestAsync(IRequest request, ISchemeHandlerResponse response, OnRequestCompletedHandler requestCompletedCallback) { //gapp:// ignore this // The 'host' portion is entirely ignored by this scheme handler. try { var uri = new Uri(request.Url); var fileName = uri.ToString().Substring(7).Replace('/', '\\').Insert(1, ":"); if (System.IO.File.Exists(fileName)) { response.ResponseStream = System.IO.File.OpenRead(fileName); response.MimeType = GetMimeType(fileName); requestCompletedCallback.BeginInvoke(requestCompletedCallback.EndInvoke, null); return(true); } } catch { } return(false); }
public bool ProcessRequestAsync(IRequest request, ISchemeHandlerResponse response, OnRequestCompletedHandler requestCompletedCallback) { var uri = new Uri(request.Url); var file = uri.Authority + uri.AbsolutePath; file = file.Replace("/", ""); if (File.Exists(file)) { var bytes = File.ReadAllBytes(file); response.ResponseStream = new MemoryStream(bytes); switch (Path.GetExtension(file)) { case ".html": response.MimeType = "text/html"; break; } requestCompletedCallback(); return(true); } return(false); }