Skip to content

Adding nullable type functionality for HttpRequest Context Type #32203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
6 commits merged into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ IEnumerator IEnumerable.GetEnumerator()
internal string ToStringWithoutPreamble()
=> ToString().Substring(LogPreamble.Length);

internal static string EscapedValueOrEmptyMarker(string potentialValue)
internal static string EscapedValueOrEmptyMarker(string? potentialValue)
// Encode space as +
=> potentialValue?.Length > 0 ? potentialValue.Replace(' ', '+') : EmptyEntry;

Expand Down
2 changes: 1 addition & 1 deletion src/Http/Http.Abstractions/src/HttpRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public abstract class HttpRequest
/// Gets or sets the Content-Type header.
/// </summary>
/// <returns>The Content-Type header.</returns>
public abstract string ContentType { get; set; }
public abstract string? ContentType { get; set; }

/// <summary>
/// Gets or sets the request body <see cref="Stream"/>.
Expand Down
2 changes: 2 additions & 0 deletions src/Http/Http.Abstractions/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*REMOVED*Microsoft.AspNetCore.Routing.RouteValueDictionary.TryAdd(string! key, object! value) -> bool
*REMOVED*static Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.UseMiddleware(this Microsoft.AspNetCore.Builder.IApplicationBuilder! app, System.Type! middleware, params object![]! args) -> Microsoft.AspNetCore.Builder.IApplicationBuilder!
*REMOVED*static Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.UseMiddleware<TMiddleware>(this Microsoft.AspNetCore.Builder.IApplicationBuilder! app, params object![]! args) -> Microsoft.AspNetCore.Builder.IApplicationBuilder!
*REMOVED*abstract Microsoft.AspNetCore.Http.HttpRequest.ContentType.get -> string!
Microsoft.AspNetCore.Http.IResult
Microsoft.AspNetCore.Http.IResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task!
Microsoft.AspNetCore.Http.Metadata.IFromBodyMetadata
Expand All @@ -18,6 +19,7 @@ Microsoft.AspNetCore.Http.Metadata.IFromServiceMetadata
Microsoft.AspNetCore.Http.Endpoint.Endpoint(Microsoft.AspNetCore.Http.RequestDelegate? requestDelegate, Microsoft.AspNetCore.Http.EndpointMetadataCollection? metadata, string? displayName) -> void
Microsoft.AspNetCore.Http.Endpoint.RequestDelegate.get -> Microsoft.AspNetCore.Http.RequestDelegate?
Microsoft.AspNetCore.Routing.RouteValueDictionary.TryAdd(string! key, object? value) -> bool
abstract Microsoft.AspNetCore.Http.HttpRequest.ContentType.get -> string?
static Microsoft.AspNetCore.Builder.UseExtensions.Use(this Microsoft.AspNetCore.Builder.IApplicationBuilder! app, System.Func<Microsoft.AspNetCore.Http.HttpContext!, Microsoft.AspNetCore.Http.RequestDelegate!, System.Threading.Tasks.Task!>! middleware) -> Microsoft.AspNetCore.Builder.IApplicationBuilder!
static Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.UseMiddleware(this Microsoft.AspNetCore.Builder.IApplicationBuilder! app, System.Type! middleware, params object?[]! args) -> Microsoft.AspNetCore.Builder.IApplicationBuilder!
static Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.UseMiddleware<TMiddleware>(this Microsoft.AspNetCore.Builder.IApplicationBuilder! app, params object?[]! args) -> Microsoft.AspNetCore.Builder.IApplicationBuilder!
2 changes: 1 addition & 1 deletion src/Http/Http/src/Internal/DefaultHttpRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public override IRequestCookieCollection Cookies
set { RequestCookiesFeature.Cookies = value; }
}

public override string ContentType
public override string? ContentType
{
get { return Headers.ContentType; }
set { Headers.ContentType = value; }
Expand Down
7 changes: 5 additions & 2 deletions src/Middleware/HttpLogging/src/MediaTypeHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ internal static class MediaTypeHelpers
Encoding.Latin1 // TODO allowed by default? Make this configurable?
};

public static bool TryGetEncodingForMediaType(string contentType, List<MediaTypeState> mediaTypeList, [NotNullWhen(true)] out Encoding? encoding)
public static bool TryGetEncodingForMediaType(string? contentType, List<MediaTypeState> mediaTypeList, [NotNullWhen(true)] out Encoding? encoding)
{
encoding = null;
if (mediaTypeList == null || mediaTypeList.Count == 0 || string.IsNullOrEmpty(contentType))
{
return false;
}

var mediaType = new MediaTypeHeaderValue(contentType);
if (!MediaTypeHeaderValue.TryParse(contentType, out var mediaType))
{
return false;
}

if (mediaType.Charset.HasValue)
{
Expand Down