Skip to content

Commit

Permalink
add mime helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
CypherPotato committed Aug 10, 2024
1 parent 1a69e86 commit fbbe34a
Show file tree
Hide file tree
Showing 4 changed files with 1,262 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Http/LogStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public class LogStream : IDisposable
private CircularBuffer<string>? _bufferingContent = null;

/// <summary>
/// Represents a <see cref="LogStream"/> that writes its output to the <see cref="Console.Out"/> stream.
/// Gets a <see cref="LogStream"/> that writes its output to the <see cref="Console.Out"/> stream.
/// </summary>
public static readonly LogStream ConsoleOutput = new LogStream(Console.Out);
public static LogStream ConsoleOutput { get => new LogStream(Console.Out); }

/// <summary>
/// Gets the defined <see cref="RotatingLogPolicy"/> for this <see cref="LogStream"/>.
Expand Down
29 changes: 29 additions & 0 deletions src/Http/MimeHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// The Sisk Framework source code
// Copyright (c) 2023 PROJECT PRINCIPIUM
//
// The code below is licensed under the MIT license as
// of the date of its publication, available at
//
// File name: MimeHelper.cs
// Repository: https://github.com/sisk-http/core

using Sisk.Core.Internal;

namespace Sisk.Core.Http;

/// <summary>
/// Provides useful helper methods for resolving mime-types from common formats.
/// </summary>
public static class MimeHelper
{
/// <summary>
/// Gets the content mime-type from the specified file extension.
/// </summary>
/// <param name="fileExtension">The file extension, with or without the initial dot.</param>
/// <param name="defaultMime">The default mime-type when the file is not found.</param>
/// <returns>The best matched mime-type, or the default if no mime-type was matched with the specified extension.</returns>
public static string GetMimeType(string fileExtension, string defaultMime = "application/octet-stream")
{
return MimeTypeList.ResolveMimeType(fileExtension.TrimStart('.').ToLower()) ?? defaultMime;
}
}
2 changes: 2 additions & 0 deletions src/Internal/HttpStatusDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Net;
using System.Runtime.CompilerServices;

namespace Sisk.Core.Internal;

Expand All @@ -21,6 +22,7 @@ static class HttpStatusDescription
internal static string? Get(HttpStatusCode code) =>
Get((int)code);

[MethodImpl(MethodImplOptions.AggressiveOptimization)]
internal static string Get(int code) =>
code switch
{
Expand Down
Loading

0 comments on commit fbbe34a

Please sign in to comment.