From fba75de4153d283709a32d9cc450633995e977ef Mon Sep 17 00:00:00 2001 From: maliming Date: Tue, 16 Jun 2026 15:18:33 +0800 Subject: [PATCH] Skip dataType override for IRemoteStreamContent in jQuery proxy generator --- .../JQuery/JQueryProxyScriptGenerator.cs | 9 ++++++++ ...ProxyScriptGenerator_ContentTypes_Tests.cs | 23 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/JQuery/JQueryProxyScriptGenerator.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/JQuery/JQueryProxyScriptGenerator.cs index ad44a98316..4502598c75 100644 --- a/framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/JQuery/JQueryProxyScriptGenerator.cs +++ b/framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/JQuery/JQueryProxyScriptGenerator.cs @@ -146,6 +146,15 @@ public class JQueryProxyScriptGenerator : IProxyScriptGenerator, ITransientDepen private static string GetJQueryDataTypeAndAcceptOverride(ActionApiDescriptionModel action) { + // jQuery doesn't natively support binary downloads, so don't override + // dataType/Accept for remote stream returns — letting the server pick the + // formatter naturally avoids forcing JSON metadata in place of the binary + // payload (which would re-introduce the original IRemoteStreamContent bug). + if (action.ReturnValue.IsRemoteStream) + { + return string.Empty; + } + var contentTypes = action.ReturnValue.ContentTypes; var isStringReturn = action.ReturnValue.Type == ReturnValueApiDescriptionModel.Create(typeof(string)).Type; diff --git a/framework/test/Volo.Abp.Http.Tests/Volo/Abp/Http/ProxyScripting/Generators/JQuery/JQueryProxyScriptGenerator_ContentTypes_Tests.cs b/framework/test/Volo.Abp.Http.Tests/Volo/Abp/Http/ProxyScripting/Generators/JQuery/JQueryProxyScriptGenerator_ContentTypes_Tests.cs index ee0a20114c..0eacd51628 100644 --- a/framework/test/Volo.Abp.Http.Tests/Volo/Abp/Http/ProxyScripting/Generators/JQuery/JQueryProxyScriptGenerator_ContentTypes_Tests.cs +++ b/framework/test/Volo.Abp.Http.Tests/Volo/Abp/Http/ProxyScripting/Generators/JQuery/JQueryProxyScriptGenerator_ContentTypes_Tests.cs @@ -93,7 +93,27 @@ public class JQueryProxyScriptGenerator_ContentTypes_Tests script.ShouldContain("dataType: 'json'"); } - private static ApplicationApiDescriptionModel BuildAppModel(string returnType, IList? contentTypes) + [Fact] + public void IsRemoteStream_Should_Skip_DataType_Override_To_Avoid_JSON_Metadata_Regression() + { + // For IRemoteStreamContent returns the API definition still advertises + // application/json (server-side default formatter list). The generator + // MUST NOT force dataType:'json' + Accept:'application/json' for these — + // doing so makes the server JSON-serialise the IRemoteStreamContent object + // and re-introduces the original IRemoteStreamContent bug. jQuery doesn't + // natively support binary downloads, so we let the legacy behavior stand. + var model = BuildAppModel( + returnType: "Volo.Abp.Content.IRemoteStreamContent", + contentTypes: new[] { "text/plain", "application/json", "text/json" }, + isRemoteStream: true); + + var script = _generator.CreateScript(model); + + script.ShouldNotContain("dataType: 'json'"); + script.ShouldNotContain("Accept: 'application/json'"); + } + + private static ApplicationApiDescriptionModel BuildAppModel(string returnType, IList? contentTypes, bool isRemoteStream = false) { var model = ApplicationApiDescriptionModel.Create(); var module = model.GetOrAddModule("app", "Default"); @@ -119,6 +139,7 @@ public class JQueryProxyScriptGenerator_ContentTypes_Tests Type = returnType, TypeSimple = returnType, ContentTypes = contentTypes, + IsRemoteStream = isRemoteStream, }, AuthorizeDatas = new List(), };