Skip to content

Fixing header parsing bug #1260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/client/impl/CommandAssembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private bool ParseHeaderFrame(in InboundFrame frame)
}
_rentedHeaderArray = totalBodyBytes != 0 ? frame.TakeoverPayload() : Array.Empty<byte>();

_headerBytes = frame.Payload;
_headerBytes = frame.Payload.Slice(12);

_remainingBodyBytes = (int)totalBodyBytes;
UpdateContentBodyState();
Expand Down
46 changes: 46 additions & 0 deletions projects/Unit/TestBasicProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
//---------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

using RabbitMQ.Client.Events;

using Xunit;

Expand Down Expand Up @@ -188,5 +195,44 @@ public void TestProperties_ReplyTo(string replyTo)
Assert.Equal(isReplyToPresent, basicProperties.IsReplyToPresent());
Assert.Equal(replyToAddress, basicProperties.ReplyToAddress?.ToString());
}

[Fact]
public void TestPropertiesRountrip_Headers()
{
// Arrange
var subject = new BasicProperties
{
Headers = new Dictionary<string, object?>()
};

var cf = new ConnectionFactory();
using (IConnection c = cf.CreateConnection())
using (IModel m = c.CreateModel())
{
QueueDeclareOk q = m.QueueDeclare();
var bp = new BasicProperties() { Headers = new Dictionary<string, object>() };
bp.Headers["Hello"] = "World";
byte[] sendBody = Encoding.UTF8.GetBytes("hi");
byte[] consumeBody = null;
var consumer = new EventingBasicConsumer(m);
var are = new AutoResetEvent(false);
string response = null;
consumer.Received += async (o, a) =>
{
response = Encoding.UTF8.GetString(a.BasicProperties.Headers["Hello"] as byte[]);
consumeBody = a.Body.ToArray();
are.Set();
await Task.Yield();
};

string tag = m.BasicConsume(q.QueueName, true, consumer);
m.BasicPublish("", q.QueueName, bp, sendBody);
bool waitResFalse = are.WaitOne(5000);
m.BasicCancel(tag);
Assert.True(waitResFalse);
Assert.Equal(sendBody, consumeBody);
Assert.Equal("World", response);
}
}
}
}