Skip to content

Commit 53996d4

Browse files
DevJonnyclaude
andcommitted
refactor: drop unused MessageHeader.StripLocalHeaders instance method
No transport calls it — they all use IsLocalHeader for inline filtering or BagWithoutLocalHeaders for whole-bag JSON serialisation. Keeping the method around invites callers to mutate the message's bag in place, which would re-introduce the InMemoryOutbox-by-reference regression that moving stripping out of the mediator just fixed. Test class renamed MessageHeaderStripLocalHeadersTests → MessageHeaderLocalHeadersTests and the two strip-specific cases rewritten against BagWithoutLocalHeaders (also asserts the original header is untouched, pinning the InMemoryOutbox-by-reference invariant). Co-Authored-By: Claude (claude-opus-4-7) <noreply@anthropic.com>
1 parent f3f176a commit 53996d4

2 files changed

Lines changed: 12 additions & 22 deletions

File tree

src/Paramore.Brighter/MessageHeader.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,6 @@ public static void RegisterLocalHeader(string name)
134134
}
135135
}
136136

137-
/// <summary>
138-
/// Removes every local-header entry (see <see cref="IsLocalHeader"/>) from
139-
/// <see cref="Bag"/>. Call on a wire-bound copy of the header to ensure
140-
/// local-only bag entries are not serialised onto the transport.
141-
/// </summary>
142-
public void StripLocalHeaders()
143-
{
144-
var locals = Volatile.Read(ref s_localHeaderNames);
145-
foreach (var name in locals)
146-
Bag.Remove(name);
147-
}
148-
149137
/// <summary>
150138
/// Returns a new dictionary containing every <see cref="Bag"/> entry whose key
151139
/// is not a local header (see <see cref="IsLocalHeader"/>). For transports that

tests/Paramore.Brighter.Core.Tests/MessageSerialisation/When_Stripping_Local_Headers_From_A_Message_Header.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace Paramore.Brighter.Core.Tests.MessageSerialisation;
44

5-
public class MessageHeaderStripLocalHeadersTests
5+
public class MessageHeaderLocalHeadersTests
66
{
77
[Fact]
8-
public void When_Stripping_Local_Headers_The_ProducerTopic_Bag_Entry_Is_Removed_And_Other_Entries_Survive()
8+
public void When_BagWithoutLocalHeaders_Removes_Local_Entries_And_Other_Entries_Survive()
99
{
1010
var header = new MessageHeader(
1111
messageId: "id-1",
@@ -14,25 +14,27 @@ public void When_Stripping_Local_Headers_The_ProducerTopic_Bag_Entry_Is_Removed_
1414
header.Bag[Message.ProducerTopicHeaderName] = "lookup.topic";
1515
header.Bag["user.key"] = "user.value";
1616

17-
header.StripLocalHeaders();
17+
var wireBag = header.BagWithoutLocalHeaders();
1818

19-
Assert.False(header.Bag.ContainsKey(Message.ProducerTopicHeaderName));
20-
Assert.True(header.Bag.ContainsKey("user.key"));
19+
Assert.False(wireBag.ContainsKey(Message.ProducerTopicHeaderName));
20+
Assert.True(wireBag.ContainsKey("user.key"));
21+
// original is untouched — InMemoryOutbox-by-reference keeps the local entry for retries
22+
Assert.True(header.Bag.ContainsKey(Message.ProducerTopicHeaderName));
2123
}
2224

2325
[Fact]
24-
public void When_Stripping_Local_Headers_With_No_Local_Bag_Entries_Then_The_Bag_Is_Unchanged()
26+
public void When_BagWithoutLocalHeaders_With_No_Local_Entries_Returns_Equivalent_Copy()
2527
{
2628
var header = new MessageHeader(
2729
messageId: "id-2",
2830
topic: new RoutingKey("a.topic"),
2931
messageType: MessageType.MT_EVENT);
3032
header.Bag["user.key"] = "user.value";
3133

32-
header.StripLocalHeaders();
34+
var wireBag = header.BagWithoutLocalHeaders();
3335

34-
Assert.Single(header.Bag);
35-
Assert.Equal("user.value", header.Bag["user.key"]);
36+
Assert.Single(wireBag);
37+
Assert.Equal("user.value", wireBag["user.key"]);
3638
}
3739

3840
[Fact]
@@ -44,7 +46,7 @@ public void When_The_Producer_Topic_Header_Name_Is_A_Local_Header()
4446
[Fact]
4547
public void When_RegisterLocalHeader_Adds_A_Custom_Key_It_Is_Recognised_And_Is_Idempotent()
4648
{
47-
const string customKey = "custom.local.header." + nameof(MessageHeaderStripLocalHeadersTests);
49+
const string customKey = "custom.local.header." + nameof(MessageHeaderLocalHeadersTests);
4850

4951
MessageHeader.RegisterLocalHeader(customKey);
5052
MessageHeader.RegisterLocalHeader(customKey); // idempotent

0 commit comments

Comments
 (0)