Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use FormFeature to populate Request.Form
* Populate ContenType and ContentLength to Headers
- Loading branch information
1 parent
baad396
commit c987f5a
Showing
6 changed files
with
63 additions
and
55 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Net.Http.Headers; | ||
|
||
namespace Alba | ||
{ | ||
public static class HeaderExtensions | ||
{ | ||
public static long? GetContentLength(this IHeaderDictionary headers) | ||
{ | ||
long length; | ||
var rawValue = headers[HeaderNames.ContentLength]; | ||
|
||
if (rawValue.Count == 1 && | ||
!string.IsNullOrWhiteSpace(rawValue[0]) && | ||
HeaderUtilities.TryParseInt64(rawValue[0], out length)) | ||
{ | ||
return length; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static void SetContentLength(this IHeaderDictionary headers, long? value) | ||
{ | ||
if (value.HasValue) | ||
{ | ||
headers[HeaderNames.ContentLength] = HeaderUtilities.FormatInt64(value.Value); | ||
} | ||
else | ||
{ | ||
headers.Remove(HeaderNames.ContentLength); | ||
} | ||
} | ||
} | ||
} |
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
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