private void RspHttpHandshakeReceive() { if (httpProxyState == null) { httpProxyState = new HttpPraser(true); } httpProxyState.httpAuthUser = _config.authUser; httpProxyState.httpAuthPass = _config.authPass; byte[] remoteHeaderSendBuffer = null; int err = httpProxyState.HandshakeReceive(_firstPacket, _firstPacketLength, ref remoteHeaderSendBuffer); if (err == 1) { _local.BeginReceive(connetionRecvBuffer, 0, _firstPacket.Length, 0, new AsyncCallback(HttpHandshakeRecv), null); } else if (err == 2) { string dataSend = httpProxyState.Http407(); byte[] httpData = System.Text.Encoding.UTF8.GetBytes(dataSend); _local.BeginSend(httpData, 0, httpData.Length, 0, new AsyncCallback(HttpHandshakeAuthEndSend), null); } else if (err == 3) { Connect(); } else if (err == 4) { Connect(); } else if (err == 0) { string dataSend = httpProxyState.Http200(); byte[] httpData = System.Text.Encoding.UTF8.GetBytes(dataSend); _local.BeginSend(httpData, 0, httpData.Length, 0, new AsyncCallback(StartConnect), null); } else if (err == 500) { string dataSend = httpProxyState.Http500(); byte[] httpData = System.Text.Encoding.UTF8.GetBytes(dataSend); _local.BeginSend(httpData, 0, httpData.Length, 0, new AsyncCallback(HttpHandshakeAuthEndSend), null); } }
private void RspHttpHandshakeReceive() { command = 1; // Set TCP connect command if (httpProxyState == null) { httpProxyState = new HttpPraser(); } if (Util.Utils.isMatchSubNet(((IPEndPoint)_connection.RemoteEndPoint).Address, "127.0.0.0/8")) { httpProxyState.httpAuthUser = ""; httpProxyState.httpAuthPass = ""; } else { httpProxyState.httpAuthUser = _config.authUser; httpProxyState.httpAuthPass = _config.authPass; } for (int i = 1; ; ++i) { int err = httpProxyState.HandshakeReceive(_firstPacket, _firstPacketLength, ref _remoteHeaderSendBuffer); if (err == 1) { if (HttpHandshakeRecv()) { break; } } else if (err == 2) { string dataSend = httpProxyState.Http407(); byte[] httpData = Encoding.UTF8.GetBytes(dataSend); _connection.Send(httpData); if (HttpHandshakeRecv()) { break; } } else if (err == 3 || err == 4) { Connect(); break; } else if (err == 0) { local_sendback_protocol = "http"; Connect(); break; } else if (err == 500) { string dataSend = httpProxyState.Http500(); byte[] httpData = Encoding.UTF8.GetBytes(dataSend); _connection.Send(httpData); if (HttpHandshakeRecv()) { break; } } if (i == 3) { Close(); break; } } }