Skip to content

Commit 9f29079

Browse files
Merge pull request #1260 from stebet/headerfix
2 parents 99a2b69 + 9816b6c commit 9f29079

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

projects/RabbitMQ.Client/client/impl/CommandAssembler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private bool ParseHeaderFrame(in InboundFrame frame)
149149
}
150150
_rentedHeaderArray = totalBodyBytes != 0 ? frame.TakeoverPayload() : Array.Empty<byte>();
151151

152-
_headerBytes = frame.Payload;
152+
_headerBytes = frame.Payload.Slice(12);
153153

154154
_remainingBodyBytes = (int)totalBodyBytes;
155155
UpdateContentBodyState();

projects/Unit/TestBasicProperties.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
//---------------------------------------------------------------------------
3131

3232
using System;
33+
using System.Collections.Generic;
34+
using System.Diagnostics;
35+
using System.Text;
36+
using System.Threading;
37+
using System.Threading.Tasks;
38+
39+
using RabbitMQ.Client.Events;
3340

3441
using Xunit;
3542

@@ -188,5 +195,44 @@ public void TestProperties_ReplyTo(string replyTo)
188195
Assert.Equal(isReplyToPresent, basicProperties.IsReplyToPresent());
189196
Assert.Equal(replyToAddress, basicProperties.ReplyToAddress?.ToString());
190197
}
198+
199+
[Fact]
200+
public void TestPropertiesRountrip_Headers()
201+
{
202+
// Arrange
203+
var subject = new BasicProperties
204+
{
205+
Headers = new Dictionary<string, object?>()
206+
};
207+
208+
var cf = new ConnectionFactory();
209+
using (IConnection c = cf.CreateConnection())
210+
using (IModel m = c.CreateModel())
211+
{
212+
QueueDeclareOk q = m.QueueDeclare();
213+
var bp = new BasicProperties() { Headers = new Dictionary<string, object>() };
214+
bp.Headers["Hello"] = "World";
215+
byte[] sendBody = Encoding.UTF8.GetBytes("hi");
216+
byte[] consumeBody = null;
217+
var consumer = new EventingBasicConsumer(m);
218+
var are = new AutoResetEvent(false);
219+
string response = null;
220+
consumer.Received += async (o, a) =>
221+
{
222+
response = Encoding.UTF8.GetString(a.BasicProperties.Headers["Hello"] as byte[]);
223+
consumeBody = a.Body.ToArray();
224+
are.Set();
225+
await Task.Yield();
226+
};
227+
228+
string tag = m.BasicConsume(q.QueueName, true, consumer);
229+
m.BasicPublish("", q.QueueName, bp, sendBody);
230+
bool waitResFalse = are.WaitOne(5000);
231+
m.BasicCancel(tag);
232+
Assert.True(waitResFalse);
233+
Assert.Equal(sendBody, consumeBody);
234+
Assert.Equal("World", response);
235+
}
236+
}
191237
}
192238
}

0 commit comments

Comments
 (0)