Skip to content
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 @@ -48,7 +48,7 @@ public RemoteAppSessionStateManager(
[LoggerMessage(EventId = 3, Level = LogLevel.Trace, Message = "Received {StatusCode} response committing remote session state")]
private partial void LogCommitResponse(HttpStatusCode statusCode);

public async Task<ISessionState> CreateAsync(HttpContextCore context, ISessionMetadata metadata)
public async Task<ISessionState> CreateAsync(HttpContextCore context, SessionAttribute metadata)
{
using var timeout = new CancellationTokenSource(_options.NetworkTimeout);
using var cts = CancellationTokenSource.CreateLinkedTokenSource(timeout.Token, context.RequestAborted, context.RequestAborted);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public AspNetCoreSessionManager(ISessionKeySerializer serializer, ILoggerFactory
_options = options;
}

public Task<ISessionState> CreateAsync(HttpContextCore context, ISessionMetadata metadata)
public Task<ISessionState> CreateAsync(HttpContextCore context, SessionAttribute metadata)
=> Task.FromResult<ISessionState>(new AspNetCoreSessionState(context.Session, _serializer, _loggerFactory, metadata.IsReadOnly, _options.Value.ThrowOnUnknownSessionKey));
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
namespace Microsoft.AspNetCore.SystemWebAdapters;

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
public sealed class BufferResponseStreamAttribute : Attribute, IBufferResponseStreamMetadata
public sealed class BufferResponseStreamAttribute : Attribute
{
public bool IsEnabled { get; set; } = true;
public bool IsDisabled { get; set; }

public int MemoryThreshold { get; set; } = 32768; // Same default as FileBufferingWriteStream

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public BufferResponseStreamMiddleware(RequestDelegate next, ILogger<BufferRespon
}

public Task InvokeAsync(HttpContextCore context)
=> context.GetEndpoint()?.Metadata.GetMetadata<IBufferResponseStreamMetadata>() is { IsEnabled: true } metadata && context.Features.Get<IHttpResponseBodyFeature>() is { } feature
=> context.GetEndpoint()?.Metadata.GetMetadata<BufferResponseStreamAttribute>() is { IsDisabled: false } metadata && context.Features.Get<IHttpResponseBodyFeature>() is { } feature
? BufferResponseStreamAsync(context, feature, metadata)
: _next(context);

private async Task BufferResponseStreamAsync(HttpContextCore context, IHttpResponseBodyFeature feature, IBufferResponseStreamMetadata metadata)
private async Task BufferResponseStreamAsync(HttpContextCore context, IHttpResponseBodyFeature feature, BufferResponseStreamAttribute metadata)
{
LogBuffering(metadata.BufferLimit, metadata.MemoryThreshold);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public enum StreamState
}

private readonly IHttpResponseBodyFeature _other;
private readonly IBufferResponseStreamMetadata _metadata;
private readonly BufferResponseStreamAttribute _metadata;

private FileBufferingWriteStream? _bufferedStream;
private PipeWriter? _pipeWriter;

public BufferedHttpResponseFeature(IHttpResponseBodyFeature other, IBufferResponseStreamMetadata metadata)
public BufferedHttpResponseFeature(IHttpResponseBodyFeature other, BufferResponseStreamAttribute metadata)
{
_other = other;
_metadata = metadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public CurrentPrincipalMiddleware(RequestDelegate next, ILogger<CurrentPrincipal
}

public Task InvokeAsync(HttpContext context)
=> context.GetEndpoint()?.Metadata.GetMetadata<ISetThreadCurrentPrincipal>() is { IsEnabled: true } ? SetUserAsync(context) : _next(context);
=> context.GetEndpoint()?.Metadata.GetMetadata<SetThreadCurrentPrincipalAttribute>() is { IsDisabled: false } ? SetUserAsync(context) : _next(context);

private async Task SetUserAsync(HttpContext context)
{
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public interface ISessionManager
/// Creates an instance of <see cref="ISessionState"/> for a given context.
/// </summary>
/// <param name="context">Current <see cref="HttpContextCore"/>.</param>
/// <param name="metadata"> Metadata for the session.</param>
Task<ISessionState> CreateAsync(HttpContextCore context, ISessionMetadata metadata);
/// <param name="metadata">Metadata for the session.</param>
Task<ISessionState> CreateAsync(HttpContextCore context, SessionAttribute metadata);
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
namespace Microsoft.AspNetCore.SystemWebAdapters;

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
public sealed class PreBufferRequestStreamAttribute : Attribute, IPreBufferRequestStreamMetadata
public sealed class PreBufferRequestStreamAttribute : Attribute
{
// Same limit as the default: https://source.dot.net/#Microsoft.AspNetCore.Http/Internal/BufferingHelper.cs,47b7015acb14f2a4
private const int DefaultBufferThreshold = 1024 * 30;

public bool IsEnabled { get; set; } = true;
public bool IsDisabled { get; set; }

public int BufferThreshold { get; set; } = DefaultBufferThreshold;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public PreBufferRequestStreamMiddleware(RequestDelegate next, ILogger<PreBufferR
}

public Task InvokeAsync(HttpContextCore context)
=> context.GetEndpoint()?.Metadata.GetMetadata<IPreBufferRequestStreamMetadata>() is { IsEnabled: true } metadata
=> context.GetEndpoint()?.Metadata.GetMetadata<PreBufferRequestStreamAttribute>() is { IsDisabled: false } metadata
? PreBufferAsync(context, metadata)
: _next(context);


private async Task PreBufferAsync(HttpContextCore context, IPreBufferRequestStreamMetadata metadata)
private async Task PreBufferAsync(HttpContextCore context, PreBufferRequestStreamAttribute metadata)
{
// TODO: Should this enforce MaxRequestBodySize? https://github.com/aspnet/AspLabs/pull/447#discussion_r827314309
LogMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
namespace Microsoft.AspNetCore.SystemWebAdapters;

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public sealed class SessionAttribute : Attribute, ISessionMetadata
public sealed class SessionAttribute : Attribute
{
public SessionBehavior Behavior { get; set; } = SessionBehavior.PreLoad;
public SessionBehavior Behavior { get; set; } = SessionBehavior.Preload;

public bool IsReadOnly { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public enum SessionBehavior
/// <summary>
/// Asynchronously loads the session for controllers with this attribute before running the controller.
/// </summary>
PreLoad,
Preload,

/// <summary>
/// Synchronously loads the session for controllers with this attribute on first use.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public SessionMiddleware(RequestDelegate next, ILogger<SessionMiddleware> logger
}

public Task InvokeAsync(HttpContextCore context)
=> context.GetEndpoint()?.Metadata.GetMetadata<ISessionMetadata>() is { Behavior: not SessionBehavior.None } metadata
=> context.GetEndpoint()?.Metadata.GetMetadata<SessionAttribute>() is { Behavior: not SessionBehavior.None } metadata
? ManageStateAsync(context, metadata)
: _next(context);

private async Task ManageStateAsync(HttpContextCore context, ISessionMetadata metadata)
private async Task ManageStateAsync(HttpContextCore context, SessionAttribute metadata)
{
LogMessage(metadata.Behavior);

Expand All @@ -47,7 +47,7 @@ private async Task ManageStateAsync(HttpContextCore context, ISessionMetadata me
#pragma warning restore CS0618 // Type or member is obsolete
#pragma warning restore CA2000 // Dispose objects before losing scope

SessionBehavior.PreLoad => await manager.CreateAsync(context, metadata),
SessionBehavior.Preload => await manager.CreateAsync(context, metadata),
var behavior => throw new InvalidOperationException($"Unknown session behavior {behavior}"),
};

Expand All @@ -68,7 +68,7 @@ private class LazySessionState : DelegatingSessionState
{
private readonly Lazy<ISessionState> _state;

public LazySessionState(HttpContextCore context, Action log, ISessionMetadata metadata, ISessionManager manager)
public LazySessionState(HttpContextCore context, Action log, SessionAttribute metadata, ISessionManager manager)
{
_state = new Lazy<ISessionState>(() =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Microsoft.AspNetCore.SystemWebAdapters;

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public sealed class SetThreadCurrentPrincipalAttribute : Attribute, ISetThreadCurrentPrincipal, ISingleThreadedRequestMetadata
public sealed class SetThreadCurrentPrincipalAttribute : Attribute
{
public bool IsEnabled { get; set; } = true;
public bool IsDisabled { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Microsoft.AspNetCore.SystemWebAdapters;

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public sealed class SingleThreadedRequestAttribute : Attribute, ISingleThreadedRequestMetadata
public sealed class SingleThreadedRequestAttribute : Attribute
{
public bool IsEnabled { get; set; } = true;
public bool IsDisabled { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class SingleThreadedRequestMiddleware
public SingleThreadedRequestMiddleware(RequestDelegate next) => _next = next;

public Task InvokeAsync(HttpContextCore context)
=> context.GetEndpoint()?.Metadata.GetMetadata<ISingleThreadedRequestMetadata>() is { IsEnabled: true }
=> context.GetEndpoint()?.Metadata.GetMetadata<SingleThreadedRequestAttribute>() is { IsDisabled: false }
? EnsureSingleThreaded(context)
: _next(context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ public static void UseSystemWebAdapters(this IApplicationBuilder app)
/// <summary>
/// Adds request stream buffering to the endpoint(s)
/// </summary>
public static TBuilder PreBufferRequestStream<TBuilder>(this TBuilder builder, IPreBufferRequestStreamMetadata? metadata = null)
public static TBuilder PreBufferRequestStream<TBuilder>(this TBuilder builder, PreBufferRequestStreamAttribute? metadata = null)
where TBuilder : IEndpointConventionBuilder
=> builder.WithMetadata(metadata ?? new PreBufferRequestStreamAttribute());

/// <summary>
/// Adds session support for System.Web adapters for the endpoint(s)
/// </summary>
public static TBuilder RequireSystemWebAdapterSession<TBuilder>(this TBuilder builder, ISessionMetadata? metadata = null)
public static TBuilder RequireSystemWebAdapterSession<TBuilder>(this TBuilder builder, SessionAttribute? metadata = null)
where TBuilder : IEndpointConventionBuilder
=> builder.WithMetadata(metadata ?? new SessionAttribute());

/// <summary>
/// Ensure response stream is buffered to enable synchronous actions on it for the endpoint(s)
/// </summary>
public static TBuilder BufferResponseStream<TBuilder>(this TBuilder builder, IBufferResponseStreamMetadata? metadata = null)
public static TBuilder BufferResponseStream<TBuilder>(this TBuilder builder, BufferResponseStreamAttribute? metadata = null)
where TBuilder : IEndpointConventionBuilder
=> builder.WithMetadata(metadata ?? new BufferResponseStreamAttribute());

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.AspNetCore.SystemWebAdapters/HttpContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class HttpContext : IServiceProvider

public static HttpContext? Current => _accessor.HttpContext;

public HttpContext(HttpContextCore context)
internal HttpContext(HttpContextCore context)
{
_context = context ?? throw new ArgumentNullException(nameof(context));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed class HttpFileCollection : NameObjectCollectionBase
{
private string[]? _keys;

public HttpFileCollection(IFormFileCollection files)
internal HttpFileCollection(IFormFileCollection files)
{
FormFiles = files;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace System.Web;

public sealed class HttpPostedFile
{
public HttpPostedFile(IFormFile file) => File = file;
internal HttpPostedFile(IFormFile file) => File = file;

internal IFormFile File { get; }

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class HttpRequest
private NameValueCollection? _params;
private HttpBrowserCapabilities? _browser;

public HttpRequest(HttpRequestCore request)
internal HttpRequest(HttpRequestCore request)
{
_request = request;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.AspNetCore.SystemWebAdapters/HttpResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class HttpResponse
private TextWriter? _writer;
private HttpCookieCollection? _cookies;

public HttpResponse(HttpResponseCore response)
internal HttpResponse(HttpResponseCore response)
{
_response = response;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.AspNetCore.SystemWebAdapters/Ref.Standard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ internal HttpResponse() { }
public System.Web.HttpCookieCollection Cookies { get { throw new System.PlatformNotSupportedException("Only support when running on ASP.NET Core or System.Web");} }
public System.Collections.Specialized.NameValueCollection Headers { get { throw new System.PlatformNotSupportedException("Only support when running on ASP.NET Core or System.Web");} }
public bool IsClientConnected { get { throw new System.PlatformNotSupportedException("Only support when running on ASP.NET Core or System.Web");} }
public bool IsRequestBeingRedirected { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw new System.PlatformNotSupportedException("Only support when running on ASP.NET Core or System.Web");} }
public bool IsRequestBeingRedirected { get { throw new System.PlatformNotSupportedException("Only support when running on ASP.NET Core or System.Web");} }
public System.IO.TextWriter Output { get { throw new System.PlatformNotSupportedException("Only support when running on ASP.NET Core or System.Web");} set { throw new System.PlatformNotSupportedException("Only support when running on ASP.NET Core or System.Web");} }
public System.IO.Stream OutputStream { get { throw new System.PlatformNotSupportedException("Only support when running on ASP.NET Core or System.Web");} }
public int StatusCode { get { throw new System.PlatformNotSupportedException("Only support when running on ASP.NET Core or System.Web");} set { throw new System.PlatformNotSupportedException("Only support when running on ASP.NET Core or System.Web");} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ public class PreBufferRequestStreamMiddlewareTests
[InlineData(true)]
[InlineData(false)]
[Theory]
public async Task RequestBuffering(bool isEnabled)
public async Task RequestBuffering(bool isDisabled)
{
// Arrange
var next = new Mock<RequestDelegate>();
using var mock = AutoMock.GetLoose(c => c.RegisterMock(next));

var logger = new Mock<ILogger<PreBufferRequestStreamMiddleware>>();

var metadata = new Mock<IPreBufferRequestStreamMetadata>();
metadata.Setup(m => m.IsEnabled).Returns(isEnabled);
var metadata = new PreBufferRequestStreamAttribute { IsDisabled = isDisabled };

var metadataCollection = new EndpointMetadataCollection(metadata.Object);
var metadataCollection = new EndpointMetadataCollection(metadata);

var endpointFeature = new Mock<IEndpointFeature>();
endpointFeature.Setup(e => e.Endpoint).Returns(new Endpoint(null, metadataCollection, null));
Expand All @@ -52,6 +51,6 @@ public async Task RequestBuffering(bool isEnabled)
await mock.Create<PreBufferRequestStreamMiddleware>().InvokeAsync(context);

// Assert
Assert.Equal(isEnabled, context.Request.Body.CanSeek);
Assert.Equal(!isDisabled, context.Request.Body.CanSeek);
}
}