void HttpDebugSocket::OnFirst()
{
	Send(
		"HTTP/1.1 200 OK\n"
		"Content-type: text/html\n"
		"Connection: close\n"
		"Server: HttpDebugSocket/1.0\n"
		"\n");
	Send(
		"<html><head><title>Echo Request</title></head>"
		"<body><h3>Request Header</h3>");
	Send(	"<form method='post' action='/test_post'>"
		"<input type='text' name='text' value='test text'><br>"
		"<input type='submit' name='submit' value=' OK '></form>");

	// enctype 'multipart/form-data'
	Sendf("<form action='/test_post' method='post' enctype='multipart/form-data'>");
	Sendf("<input type=file name=the_file><br>");
	Sendf("<input type=text name=the_name><br>");
	Sendf("<input type=submit name=submit value=' test form-data '>");
	Sendf("</form>");

	Send(	"<pre style='background: #e0e0e0'>");
	Send(GetMethod() + " " + GetUrl() + " " + GetHttpVersion() + "\n");
}
void HttpClientSocket::OnFirst()
{
	if (!IsResponse())
	{
		Handler().LogError(this, "OnFirst", 0, "Response expected but not received - aborting", LOG_LEVEL_FATAL);
		SetCloseAndDelete();
	}
	m_content = GetHttpVersion() + " " + GetStatus() + " " + GetStatusText() + "\r\n";
}
int CLuaHttpServer::OnReceive(WORD nClient, char* pData, DWORD dwDataLen)
{
	string strMethod = GetMethod(pData);
	string strPathFile = GetPathFile(pData);
	string strVersion = GetHttpVersion(pData);

	string strFilePath = m_strVirtualPath + strPathFile;
	char szFileContent[FILE_MAX_LEN];
	DWORD dwFileLen = 0;
	LoadLocationFile(szFileContent, dwFileLen, strFilePath.c_str());

	char szHeader[HEADER_MAX_LEN];
	sprintf(szHeader, 
		"HTTP/1.1 %d %s\r\n"
		"Server: %s\r\n"
		"Content-Length: %d\r\n"
		"Content-Type: %s\r\n"
		"Connection: close\r\n"
		"Connection: keep-alive\r\n\r\n",
		200, "OK",
		"LHS/1.0 Lua/5.1",
		dwFileLen,
		"text/html");
	size_t nHeaderSize = strlen(szHeader);

	char szSendBuffer[FILE_MAX_LEN+HEADER_MAX_LEN+HEADER_MAX_LEN];
	memcpy(szSendBuffer, szHeader, nHeaderSize);
	if (szFileContent > 0)
	{
		memcpy(szSendBuffer+nHeaderSize, szFileContent, dwFileLen);
	}

	SendData(nClient, szSendBuffer, (u_long)(nHeaderSize+dwFileLen));

	return 0;
}