private bool ServeEmbeddedResource(HTTPResponse response, Assembly assembly, string strippedResourceName) { string fullResourceName = FullResourceName(assembly, strippedResourceName); if (!string.IsNullOrEmpty(fullResourceName)) { try { using (Stream resourceStream = assembly.GetManifestResourceStream(fullResourceName)) if (resourceStream != null) { string extension = Path.GetExtension(strippedResourceName); response.SetHeader(HTTPHeader.ContentType, MIMETypeMap.GetMIMEType(extension)); response.SetHeader(HTTPHeader.LastModified, File.GetLastWriteTime(assembly.Location).ToHTTPDate()); response.WriteStream(resourceStream); return(true); } } catch { } } return(false); }
public void HandleRequest(HTTPRequest request, HTTPResponse response) { if (request.Subroute == "") { //If there really is no file requested, then we send a 404! response.WriteError(HTTPStatusCode.NotFound, "Not Found"); return; } lock (_dictionary) { if (_dictionary.TryGetValue(request.Subroute, out MemoryStream resource)) { resource.Position = 0; response.WriteStream(resource); response.SetHeader("Cache-Control", "no-cache, no-store, must-revalidate"); response.SetHeader("Pragma", "no-cache"); response.SetHeader("Expires", "0"); } else { response.WriteError(HTTPStatusCode.NotFound, "Not Found"); } } }
private void ServeFile(string filePath, HTTPResponse response) { string extension = Path.GetExtension(filePath); response.SetHeader(HTTPHeader.ContentType, MIMETypeMap.GetMIMEType(extension)); response.SetHeader(HTTPHeader.LastModified, System.IO.File.GetLastWriteTime(filePath).ToHTTPDate()); using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) response.WriteStream(stream); }
private void ServeFile(string filePath, HTTPResponse response) { string extension = Path.GetExtension(filePath); response.SetHeader(HTTPHeader.ContentType, MIMETypeMap.GetMIMEType(extension)); response.SetHeader(HTTPHeader.LastModified, System.IO.File.GetLastWriteTime(filePath).ToHTTPDate()); FileStream file = File.Open(filePath, FileMode.Open); response.WriteStream(file); file.Close(); }
private bool ServeEmbeddedResource(HTTPResponse response, Assembly assembly, string strippedResourceName) { string fullResourceName = FullResourceName(assembly, strippedResourceName); if (!string.IsNullOrEmpty(fullResourceName)) try { using (Stream resourceStream = assembly.GetManifestResourceStream(fullResourceName)) if (resourceStream != null) { string extension = Path.GetExtension(strippedResourceName); response.SetHeader(HTTPHeader.ContentType, MIMETypeMap.GetMIMEType(extension)); response.SetHeader(HTTPHeader.LastModified, File.GetLastWriteTime(assembly.Location).ToHTTPDate()); response.WriteStream(resourceStream); return true; } } catch { } return false; }
private void ServeFile(string filePath, HTTPResponse response) { string extension = Path.GetExtension(filePath); response.SetHeader(HTTPHeader.ContentType, MIMETypeMap.GetMIMEType(extension)); response.SetHeader(HTTPHeader.LastModified, System.IO.File.GetLastWriteTime(filePath).ToHTTPDate()); FileStream file = File.Open(filePath, FileMode.Open); response.WriteStream(file); file.Close(); }