From 09d3101c37cfb80565b56751b8c3364034868ee0 Mon Sep 17 00:00:00 2001 From: Waldek Mastykarz Date: Wed, 21 Oct 2026 15:57:19 +0200 Subject: [PATCH] Return 204 No Content from POST /proxy/mockRequest The mock request has already been processed when the response is sent, so 202 Accepted is misleading. Closes #1972 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 250031cc-f525-4369-a32a-0bd181e6f66a --- DevProxy.Tests/ProxyControllerTests.cs | 29 ++++++++++++++++++++++ DevProxy/ApiControllers/ProxyController.cs | 4 +-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 DevProxy.Tests/ProxyControllerTests.cs diff --git a/DevProxy.Tests/ProxyControllerTests.cs b/DevProxy.Tests/ProxyControllerTests.cs new file mode 100644 index 000000000..c9158900c --- /dev/null +++ b/DevProxy.Tests/ProxyControllerTests.cs @@ -0,0 +1,29 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Security.Cryptography; +using System.Security.Cryptography.X509Certificates; +using DevProxy.ApiControllers; +using Microsoft.AspNetCore.Mvc; +using Xunit; + +namespace DevProxy.Tests; + +public sealed class ProxyControllerTests +{ + [Fact] + public async Task RaiseMockRequestAsync_ReturnsNoContentAfterMockRequestCompletes() + { + var stateController = new FakeProxyStateController(); + using var rsa = RSA.Create(2048); + var request = new CertificateRequest("CN=test", rsa, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1); + using var cert = request.CreateSelfSigned(DateTimeOffset.UtcNow, DateTimeOffset.UtcNow.AddDays(1)); + var controller = new ProxyController(stateController, new FakeProxyConfiguration(), cert); + + var result = await controller.RaiseMockRequestAsync(CancellationToken.None); + + _ = Assert.IsType(result); + Assert.Equal(1, stateController.MockRequestCalls); + } +} diff --git a/DevProxy/ApiControllers/ProxyController.cs b/DevProxy/ApiControllers/ProxyController.cs index 31b55b0c9..3332dab6c 100644 --- a/DevProxy/ApiControllers/ProxyController.cs +++ b/DevProxy/ApiControllers/ProxyController.cs @@ -57,11 +57,11 @@ public async Task SetAsync([FromBody] ProxyInfo proxyInfo, Cancel [HttpPost("mockRequest")] #pragma warning disable CA1030 - public async Task RaiseMockRequestAsync(CancellationToken cancellationToken) + public async Task RaiseMockRequestAsync(CancellationToken cancellationToken) #pragma warning restore CA1030 { await _proxyStateController.MockRequestAsync(cancellationToken); - Response.StatusCode = 202; + return NoContent(); } [HttpPost("stopProxy")]