private void WritePacketTest(byte method = 0x02,
string protocol = "HTTP/1.1",
string req_uri = "/",
string remote_addr ="::1",
string remote_host ="::1",
string server_name ="localhost",
ushort server_port = 80,
bool is_ssl = false,
int num_headers=1)
{
//create request in bytes. first create user data
int pos = 0;
byte[] aUserData = new byte[BonCodeAJP13Settings.MAX_BONCODEAJP13_PACKET_LENGTH]; //allocate full number of bytes for processing
//add a mapping prefix if one is provided
if (BonCodeAJP13Settings.BONCODEAJP13_PATH_PREFIX.Length > 2)
{
req_uri = BonCodeAJP13Settings.BONCODEAJP13_PATH_PREFIX.Length + "/" + req_uri;
}
// set protocol required data points
// ============================================================
pos = SetByte(aUserData, BonCodeAJP13ServerPacketType.SERVER_FORWARD_REQUEST, pos); // all have to start with this
pos = SetByte(aUserData, BonCodeAJP13HTTPMethods.BONCODEAJP13_GET, pos); //method: e.g. we have clicked on URL
pos = SetString(aUserData, protocol, pos); //protocol
pos = SetString(aUserData, req_uri, pos); //uri
pos = SetString(aUserData, remote_addr, pos); //remote addr
pos = SetString(aUserData, remote_host, pos); //remote host
pos = SetString(aUserData, server_name, pos); //server name
pos = SetInt16(aUserData, server_port, pos); //port
pos = SetByte(aUserData, Convert.ToByte(is_ssl), pos); //is ssl
pos = SetInt16(aUserData, System.Convert.ToUInt16(num_headers), pos); //number of headers
//add content lenth as the only header.
pos = SetByte(aUserData, 0xA0, pos); //header prefix (once per header)
pos = SetByte(aUserData, BonCodeAJP13HTTPHeaders.BONCODEAJP13_CONTENT_LENGTH, pos); //id of header
pos = SetString(aUserData, "0", pos); //add length as a string value
//add packet terminator
pos = SetByte(aUserData, 0xFF, pos); //marks the end of user packet
//assess length of package and type
int pLength = pos; // true length of user data
p_UserDataLength = Convert.ToUInt16(pLength);
//assemble full package now in the final array container of the object
p_ByteStore = new byte[pos + 4]; // this is the true length as we add magic and length bytes
int pos2 = 0;
pos2 = SetByte(p_ByteStore, BonCodeAJP13Markers.BONCODEAJP13_PACKET_START, pos2);
pos2 = SetByte(p_ByteStore, BonCodeAJP13Markers.BONCODEAJP13_PACKET_START2, pos2);
pos2 = SetUInt16(p_ByteStore, p_UserDataLength, pos2);
Array.Copy(aUserData, 0, p_ByteStore, 4, pos); //only copy relevant data values from temporary store
//determine overall packet length
p_PacketLength = p_ByteStore.Length;
}