microsoft / BCApps

Repository for collaboration on Microsoft Dynamics 365 Business Central applications.
https://microsoft.github.io/BCApps/
MIT License
308 stars 147 forks source link

[Bug]: HttpContent.SetHeader failing when secret header already exists #1479

Open vody opened 3 months ago

vody commented 3 months ago

Describe the issue

The "Http Content" codeunit throws an error message when content is defined from SecretText.

Error message: 
Cannot add value because the header 'Content-Type' does not support multiple values.

AL call stack: 
"Http Content Impl."(CodeUnit 2355).SetHeader line 12 - System Application by Microsoft
"Http Content Impl."(CodeUnit 2355).SetContentTypeHeader line 4 - System Application by Microsoft
"Http Content Impl."(CodeUnit 2355).SetContent line 6 - System Application by Microsoft
"Http Content"(CodeUnit 2354).SetContent line 2 - System Application by Microsoft
"Http Content"(CodeUnit 2354).Create line 2 - System Application by Microsoft\"Http Content"(CodeUnit 2354).Create line 2 - System Application by Microsoft

This happens because inside "Http Content Impl.".SetHeader procedure Headers.Contains(Name) condition will return false for a secret header, which will be automatically created when we set a content from the SecretText value.

Expected behavior

Content will be defined with a new header without error.

Steps to reproduce

codeunit 50000 SetHeader
{
    trigger OnRun()
    var
        HttpContent: Codeunit "Http Content";
    begin
        HttpContent.Create(SecretStrSubstNo('anything'));
    end;
}

Additional context

No response

I will provide a fix for a bug

JesperSchulz commented 1 month ago

@ajkauffmann has agreed to include this in a pull request he is working on anyway 🥳 I cannot assign it to him (seems I can only assign to people who have been active on the issue), but consider it assigned 😉

ajkauffmann commented 1 month ago

I'm active now. 😊 Yes, happy to take this one!

JesperSchulz commented 1 month ago

And now I could assign you 🥳

vody commented 2 weeks ago

@ajkauffmann thank you for picking this one. We tried to use it internally to promote open-source contribution within an organization but it was pushed down in priority.