Haproxy header 与预期不同

Haproxy header differs from what is expected

我正在使用 Haproxy and 需要从 TCP 流中读取 v2 header,根据规范,它应该包含以下前 13 个字节:

\x0D\x0A\x0D\x0A\x00\x0D\x0A\x51\x55\x49\x54\x0A\x02

字节

{byte[13]}
[0]: 13
[1]: 10
[2]: 13
[3]: 10
[4]: 0
[5]: 13
[6]: 10
[7]: 81
[8]: 85
[9]: 73
[10]: 84
[11]: 10
[12]: 2

然而我得到

[0]: 13
[1]: 10
[2]: 0
[3]: 13
[4]: 10
[5]: 81
[6]: 85
[7]: 73
[8]: 84
[9]: 10
[10]: 33
[11]: 17
[12]: 0

我的阅读似乎确实缺少规范中的前两个字节 13 10,但是结尾似乎也不同,我似乎无法弄清楚为什么...

更令人困惑的是我看不到 from IP 地址 (54.219.177.232) 也看不到 to (45.32.136.69) 在 header 的任何地方都 supposed to be 17th byte onward

Count = 91
[0]: 12
[1]: 180
[2]: 183
[3]: 211
[4]: 173
[5]: 172
[6]: 31
[7]: 23
[8]: 237
[9]: 228
[10]: 70
[11]: 1
[12]: 187
[13]: 22
[14]: 3
[15]: 1
[16]: 0
[17]: 178
[18]: 1
[19]: 0
[20]: 0
[21]: 174
[22]: 3
[23]: 3
[24]: 65
[25]: 71
[26]: 172
[27]: 83
[28]: 43
[29]: 146
[30]: 158
[31]: 30
[32]: 150
[33]: 85
[34]: 84
[35]: 34
[36]: 158
[37]: 111
[38]: 242
[39]: 247
[40]: 173
[41]: 198
[42]: 13
[43]: 133
[44]: 9
[45]: 39
[46]: 111
[47]: 9
[48]: 44
[49]: 64
[50]: 232
[51]: 25
[52]: 14
[53]: 51
[54]: 110
[55]: 76
[56]: 0
[57]: 0
[58]: 32
[59]: 74
[60]: 74
[61]: 192
[62]: 43
[63]: 192
[64]: 47
[65]: 192
[66]: 44
[67]: 192
[68]: 48
[69]: 204
[70]: 169
[71]: 204
[72]: 168
[73]: 204
[74]: 20
[75]: 204
[76]: 19
[77]: 192
[78]: 19
[79]: 192
[80]: 20
[81]: 0
[82]: 156
[83]: 0
[84]: 157
[85]: 0
[86]: 47
[87]: 0
[88]: 53
[89]: 0
[90]: 10`

读取 header 的代码如下所示:

var childSocketThread = new Thread(() =>
{

var getOrPostHttp1Acc = new List<byte>();
var getOrPostHttp1 = new byte[1];
while (getOrPostHttp1[0] != 10)
{
socket.Receive(getOrPostHttp1);
getOrPostHttp1Acc.Add(getOrPostHttp1[0]);
}
bool isGet = Encoding.ASCII.GetString(getOrPostHttp1Acc.ToArray()).ToUpper().Contains("GET");
byte[] proxyv2headerIdentifier = new byte[13];
socket.Receive(proxyv2headerIdentifier);
var proxyv2header = new List<byte>();
var proxyv2HeaderBuffer = new byte[1];
    if(proxyv2headerIdentifier.SequenceEqual(proxyv2HeaderStartRequence))//TODO:uncomment this, hardcoded (true) is only for testing 
{
while (proxyv2HeaderBuffer[0] != 10)
{
socket.Receive(proxyv2HeaderBuffer);
proxyv2header.Add(proxyv2HeaderBuffer[0]);
}

string headerString = $"proxyv2:{Encoding.ASCII.GetString(proxyv2header.ToArray())}";
byte[] bodyBuff = new byte[0];
byte[] buffer = new byte[1];
int contentLength = 0;
while (!headerString.Contains("\r\n\r\n"))
//at this point header is read into proxyv2header ....

我哪里看错规范了,或者做错了什么?

好的,我自己想出了这个...

错误是首先阅读了 http 方法(如果它是 GETPOST)haproxy 不是从那个开始的...所以删除方法 read var getOrPostHttp1Acc = new List<byte>(); var getOrPostHttp1 = new byte[1]; while (getOrPostHttp1[0] != 10) { socket.Receive(getOrPostHttp1); getOrPostHttp1Acc.Add(getOrPostHttp1[0]); } bool isGet = Encoding.ASCII.GetString(getOrPostHttp1Acc.ToArray()).ToUpper().Contains("GET");

并将开始序列减少到 12 个字节做到了...

关于IP,一直隐藏在众目睽睽之下...

(检查字节 4-7)

希望这能为您节省一些时间。