public void SetHTML(string html) { if (dataIn != null) { dataIn.Dispose(); } dataIn = ResourceHandler.GetMemoryStream(html, Encoding.UTF8); }
IResourceHandler Error(string error, HttpStatusCode code) { var stream = ResourceHandler.GetMemoryStream(error, Encoding.UTF8); var resourceHandler = ResourceHandler.FromStream(stream); resourceHandler.StatusCode = (int)code; Logger.Error("[OVERLAY] Load Error for plugin:// scheme: " + error); return(resourceHandler); }
public override bool ProcessRequestAsync(IRequest request, ICallback callback) { var uri = new Uri(request.Url); var fileName = uri.AbsolutePath; Task.Run(() => { using (callback) { Stream stream = null; if (string.Equals(fileName, "/PostDataTest.html", StringComparison.OrdinalIgnoreCase)) { var postDataElement = request.PostData.Elements.FirstOrDefault(); stream = ResourceHandler.GetMemoryStream("Post Data: " + (postDataElement == null ? "null" : postDataElement.GetBody()), Encoding.UTF8); } if (string.Equals(fileName, "/PostDataAjaxTest.html", StringComparison.OrdinalIgnoreCase)) { var postData = request.PostData; if (postData == null) { stream = ResourceHandler.GetMemoryStream("Post Data: null", Encoding.UTF8); } else { var postDataElement = postData.Elements.FirstOrDefault(); stream = ResourceHandler.GetMemoryStream("Post Data: " + (postDataElement == null ? "null" : postDataElement.GetBody()), Encoding.UTF8); } } if (stream == null) { callback.Cancel(); } else { //Reset the stream position to 0 so the stream can be copied into the underlying unmanaged buffer stream.Position = 0; //Populate the response values - No longer need to implement GetResponseHeaders (unless you need to perform a redirect) ResponseLength = stream.Length; MimeType = "text/html"; StatusCode = (int)HttpStatusCode.OK; Stream = stream; callback.Continue(); } } }); return(true); }
bool IResourceHandler.ProcessRequest(IRequest request, ICallback callback) { // The 'host' portion is entirely ignored by this scheme handler. var uri = new Uri(request.Url); var fileName = uri.AbsolutePath; if (string.Equals(fileName, "/PostDataTest.html", StringComparison.OrdinalIgnoreCase)) { var postDataElement = request.PostData.Elements.FirstOrDefault(); stream = ResourceHandler.GetMemoryStream("Post Data: " + (postDataElement == null ? "null" : postDataElement.GetBody()), Encoding.UTF8); mimeType = "text/html"; callback.Continue(); return(true); } if (string.Equals(fileName, "/PostDataAjaxTest.html", StringComparison.OrdinalIgnoreCase)) { var postData = request.PostData; if (postData == null) { stream = ResourceHandler.GetMemoryStream("Post Data: null", Encoding.UTF8); mimeType = "text/html"; callback.Continue(); } else { var postDataElement = postData.Elements.FirstOrDefault(); stream = ResourceHandler.GetMemoryStream("Post Data: " + (postDataElement == null ? "null" : postDataElement.GetBody()), Encoding.UTF8); mimeType = "text/html"; callback.Continue(); } return(true); } if (string.Equals(fileName, "/EmptyResponseFilterTest.html", StringComparison.OrdinalIgnoreCase)) { stream = null; mimeType = "text/html"; callback.Continue(); return(true); } string resource; if (ResourceDictionary.TryGetValue(fileName, out resource) && !string.IsNullOrEmpty(resource)) { Task.Run(() => { using (callback) { var bytes = Encoding.UTF8.GetBytes(resource); stream = new MemoryStream(bytes); var fileExtension = Path.GetExtension(fileName); mimeType = ResourceHandler.GetMimeType(fileExtension); callback.Continue(); } }); return(true); } else { callback.Dispose(); } return(false); }