-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from ILepekhov/feature/reducing-memory-allocat…
…ions-in-TusHeaders Reduced memory allocations while checking if a custom header is not reserved.
- Loading branch information
Showing
2 changed files
with
56 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,56 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace BirdMessenger.Constants; | ||
|
||
internal static class TusHeaders | ||
public static class TusHeaders | ||
{ | ||
private static readonly HashSet<string> TusReservedWords = new(StringComparer.OrdinalIgnoreCase); | ||
|
||
static TusHeaders() | ||
{ | ||
TusReservedWords.Add(UploadLength.ToLower()); | ||
TusReservedWords.Add(UploadOffset.ToLower()); | ||
TusReservedWords.Add(UploadMetadata.ToLower()); | ||
TusReservedWords.Add(UploadDeferLength.ToLower()); | ||
TusReservedWords.Add(ContentType.ToLower()); | ||
TusReservedWords.Add(UploadChecksum.ToLower()); | ||
TusReservedWords.Add(TusResumable.ToLower()); | ||
TusReservedWords.Add(UploadConcat.ToLower()); | ||
TusReservedWords.Add(TusVersion.ToLower()); | ||
TusReservedWords.Add(TusMaxSize.ToLower()); | ||
TusReservedWords.Add(TusExtension.ToLower()); | ||
TusReservedWords.Add(UploadLength); | ||
TusReservedWords.Add(UploadOffset); | ||
TusReservedWords.Add(UploadMetadata); | ||
TusReservedWords.Add(UploadDeferLength); | ||
TusReservedWords.Add(ContentType); | ||
TusReservedWords.Add(UploadChecksum); | ||
TusReservedWords.Add(TusResumable); | ||
TusReservedWords.Add(UploadConcat); | ||
TusReservedWords.Add(TusVersion); | ||
TusReservedWords.Add(TusMaxSize); | ||
TusReservedWords.Add(TusExtension); | ||
} | ||
|
||
public const string UploadLength = "Upload-Length"; | ||
|
||
public const string UploadOffset = "Upload-Offset"; | ||
|
||
public const string UploadMetadata = "Upload-Metadata"; | ||
|
||
public const string TusResumable = "Tus-Resumable"; | ||
|
||
public const string Location = "Location"; | ||
|
||
public const string UploadDeferLength = "Upload-Defer-Length"; | ||
|
||
public const string ContentType = "Content-Type"; | ||
|
||
public const string UploadChecksum = "Upload-Checksum"; | ||
|
||
public const string UploadConcat = "Upload-Concat"; | ||
|
||
public const string UploadContentTypeValue= "application/offset+octet-stream"; | ||
|
||
public const string TusVersion = "Tus-Version"; | ||
|
||
public const string TusMaxSize = "Tus-Max-Size"; | ||
|
||
public const string TusExtension = "Tus-Extension"; | ||
|
||
public static bool IsReserved(string headerName) | ||
{ | ||
return string.IsNullOrWhiteSpace(headerName) is false && | ||
TusReservedWords.Contains(headerName); | ||
} | ||
internal static readonly HashSet<string> TusReservedWords = new(); | ||
|
||
internal const string UploadLength = "Upload-Length"; | ||
|
||
internal const string UploadOffset = "Upload-Offset"; | ||
|
||
internal const string UploadMetadata = "Upload-Metadata"; | ||
|
||
internal const string TusResumable = "Tus-Resumable"; | ||
|
||
internal const string Location = "Location"; | ||
|
||
internal const string UploadDeferLength = "Upload-Defer-Length"; | ||
|
||
internal const string ContentType = "Content-Type"; | ||
|
||
internal const string UploadChecksum = "Upload-Checksum"; | ||
|
||
internal const string UploadConcat = "Upload-Concat"; | ||
|
||
internal const string UploadContentTypeValue= "application/offset+octet-stream"; | ||
|
||
internal const string TusVersion = "Tus-Version"; | ||
|
||
internal const string TusMaxSize = "Tus-Max-Size"; | ||
|
||
internal const string TusExtension = "Tus-Extension"; | ||
|
||
|
||
} | ||
} |