Browse Source

Skip dataType override for IRemoteStreamContent in jQuery proxy generator

pull/25639/head
maliming 4 months ago
parent
commit
fba75de415
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 9
      framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/JQuery/JQueryProxyScriptGenerator.cs
  2. 23
      framework/test/Volo.Abp.Http.Tests/Volo/Abp/Http/ProxyScripting/Generators/JQuery/JQueryProxyScriptGenerator_ContentTypes_Tests.cs

9
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;

23
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<string>? 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<string>? 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<AuthorizeDataApiDescriptionModel>(),
};

Loading…
Cancel
Save