CefSharp.ResourceHandler.GetMimeType C# (CSharp) Method

GetMimeType() public static method

Gets the MIME type of the content.
extension
public static GetMimeType ( string extension ) : string
extension string The extension.
return string
        public static string GetMimeType(string extension)
        {
            if (extension == null)
            {
                throw new ArgumentNullException("extension");
            }
            if (!extension.StartsWith("."))
            {
                extension = "." + extension;
            }
            string mime;
            return Mappings.TryGetValue(extension, out mime) ? mime : "application/octet-stream";
        }

Usage Example

示例#1
0
        void IResourceHandler.GetResponseHeaders(IResponse response, out long responseLength, out string redirectUrl)
        {
            responseLength = -1;
            redirectUrl    = null;

            response.StatusCode = _stream != null ? 200 : 404;
            response.StatusText = "OK";

            if (response.StatusCode == 200)
            {
                response.MimeType = CefResourceHandler.GetMimeType(Path.GetExtension(_resourcePath));
            }

            if (_stream?.CanSeek == true)
            {
                responseLength = _stream.Length;
            }
        }