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 @@ -291,6 +291,8 @@ internal HttpResponse() { }
public void ClearContent() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public void ClearHeaders() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public void End() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public void Flush() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public System.Threading.Tasks.Task FlushAsync() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public void Redirect(string url) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public void Redirect(string url, bool endResponse) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public void RedirectPermanent(string url) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.AspNetCore.SystemWebAdapters/HttpResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
Expand Down Expand Up @@ -252,6 +253,10 @@ private string ResolvePath(string url)

public void SetCookie(HttpCookie cookie) => Cookies.Set(cookie);

public void Flush() => _response.Body.Flush();

public Task FlushAsync() => _response.Body.FlushAsync(_response.HttpContext.RequestAborted);

public void End() => AdapterFeature.EndAsync().GetAwaiter().GetResult();

public void Write(char ch) => Output.Write(ch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using AutoFixture;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -173,6 +174,45 @@ public void EndNoFeature()
Assert.Throws<InvalidOperationException>(() => response.End());
}

[Fact]
public void Flush()
{
// Arrange
var responseCore = new Mock<HttpResponseCore>();
var stream = new Mock<Stream>();
responseCore.Setup(r => r.Body).Returns(stream.Object);

var response = new HttpResponse(responseCore.Object);

// Act
response.Flush();

// Assert
stream.Verify(s => s.Flush(), Times.Once);
}

[Fact]
public async Task FlushAsync()
{
// Arrange
using var tcs = new CancellationTokenSource();
var contextCore = new Mock<HttpContextCore>();
contextCore.Setup(s => s.RequestAborted).Returns(tcs.Token);

var responseCore = new Mock<HttpResponseCore>();
var stream = new Mock<Stream>();
responseCore.Setup(r => r.Body).Returns(stream.Object);
responseCore.Setup(r => r.HttpContext).Returns(contextCore.Object);

var response = new HttpResponse(responseCore.Object);

// Act
await response.FlushAsync();

// Assert
stream.Verify(s => s.FlushAsync(tcs.Token), Times.Once);
}

[Fact]
public void ContentType()
{
Expand Down