HAProxy的头从所预期

HAProxy的头从所预期

问题描述:

我与Haproxy and需要读取TCP流中的V2头的工作不同,根据符合规范它应该有前13个字节以下:HAProxy的头从所预期

\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)无处头它们是读取头看起来以下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` 

代码:

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的不与启动...所以去除方法读取 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,它在众目睽睽下这一切的时候躲在...

enter image description here

(校验字节4-7) enter image description here

希望这可以节省一些时间。