Index: /trunk/include/CRXHttpHeader.h
===================================================================
--- /trunk/include/CRXHttpHeader.h	(revision 46)
+++ /trunk/include/CRXHttpHeader.h	(revision 46)
@@ -0,0 +1,30 @@
+/**
+ * CRXHttpHeader.h
+ */
+#ifndef __CRXHTTPMESSAGE_H__
+#define __CRXHTTPMESSAGE_H__
+
+#include <string>
+
+#define CRLF				"\r\n"
+#define CRLF2				"\r\n\r\n"	
+
+class CRXHttpHeader
+{
+protected:
+	std::string	mHttpHeader;
+	std::string	mHttpVersion;
+
+public:
+	CRXHttpHeader			(void);
+	virtual ~CRXHttpHeader	(void);
+
+protected:
+	virtual void	Parse	(void) = 0;
+
+public:
+	void			Set		(const char * aHeader);
+	std::string		Get		(void) const;
+};
+
+#endif // #ifndef __CRXHTTPMESSAGE_H__
Index: /trunk/include/CRXHttpRequest.h
===================================================================
--- /trunk/include/CRXHttpRequest.h	(revision 45)
+++ /trunk/include/CRXHttpRequest.h	(revision 46)
@@ -5,7 +5,7 @@
 #define __CRXHTTPREQUEST_H__
 
-#include "CRXHttpMessage.h"
+#include "CRXHttpHeader.h"
 
-class CRXHttpRequest : public CRXHttpMessage
+class CRXHttpRequest : public CRXHttpHeader
 {
 private:
@@ -25,5 +25,4 @@
 	void				Parse				(void);
 	void				ParseFileExtension	(void);
-	void				Reset				(void);
 
 public:
Index: /trunk/include/CRXHttpResponse.h
===================================================================
--- /trunk/include/CRXHttpResponse.h	(revision 45)
+++ /trunk/include/CRXHttpResponse.h	(revision 46)
@@ -5,5 +5,7 @@
 #define __CRXHTTPRESPONSE_H__
 
-#include "CRXHttpMessage.h"
+#include "CRXHttpHeader.h"
+
+#include <vector>
 
 #define ERROR_HTTP_RESPONSE									-4000
@@ -13,16 +15,12 @@
 #define ERROR_HTTP_RESPONSE_FAILED_TO_PARSE_CONTENT			ERROR_HTTP_RESPONSE - 4
 
-class CRXHttpResponse : public CRXHttpMessage
+class CRXHttpResponse : public CRXHttpHeader
 {
 private:
-	int			mStatusCode;
-	std::string	mStatusString;
-	bool		mIsChunked;		/* Transfer-Encoding */
-	int			mContentLength;
-
-	struct __content_body__ {
-		char	* mBody;
-		int		mLength;
-	} mContent;
+	int					mStatusCode;
+	std::string			mStatusString;
+	bool				mIsChunked;		/* Transfer-Encoding */
+	unsigned int		mContentLength;
+	std::vector <char>	mContent;
 
 public:
@@ -33,5 +31,4 @@
 	void				Parse				(void);
 	void				Reset				(void);
-	void				ResetContent		(void);
 
 public:
@@ -39,7 +36,5 @@
 
 	bool				IsChunked			(void) const;
-	int					SetResponseAll		(const char	* aHttpResponse,
-											 const int	aResponseLength);
-	void				SetHeader			(const char	* aHttpResponse);
+	void				SetHeader			(const char	* aHeader);
 	std::string			GetHeader			(void) const;
 	int					SetContent			(const char	* aContent,
Index: /trunk/include/CRXProxy.h
===================================================================
--- /trunk/include/CRXProxy.h	(revision 45)
+++ /trunk/include/CRXProxy.h	(revision 46)
@@ -7,5 +7,5 @@
 #include "CRXException.h"
 #include "CRXSocket.h"
-#include "CRXHttpMessage.h"
+#include "CRXHttpHeader.h"
 #include "CRXHttpRequest.h"
 #include "CRXHttpResponse.h"
Index: /trunk/src/CRXHttpHeader.cpp
===================================================================
--- /trunk/src/CRXHttpHeader.cpp	(revision 46)
+++ /trunk/src/CRXHttpHeader.cpp	(revision 46)
@@ -0,0 +1,42 @@
+/**
+ * CRXHttpHeader.cpp
+ */
+#ifdef _WIN32
+# pragma warning (disable:4996)
+#endif
+
+#include "CRXHttpHeader.h"
+
+CRXHttpHeader::CRXHttpHeader (void)
+{
+	/*----------------------------------------------------------------*/
+	/*----------------------------------------------------------------*/
+}
+
+CRXHttpHeader::~CRXHttpHeader (void)
+{
+	/*----------------------------------------------------------------*/
+	/*----------------------------------------------------------------*/
+}
+
+void
+CRXHttpHeader::Set (const char * aHeader)
+{
+	/*----------------------------------------------------------------*/
+	if (aHeader == NULL)
+		return ;
+
+	mHttpHeader.assign (aHeader);
+
+	this->Parse ();
+	/*----------------------------------------------------------------*/
+}
+
+std::string
+CRXHttpHeader::Get (void) const
+{
+	/*----------------------------------------------------------------*/
+	/*----------------------------------------------------------------*/
+
+	return mHttpHeader;
+}
Index: /trunk/src/CRXHttpRequest.cpp
===================================================================
--- /trunk/src/CRXHttpRequest.cpp	(revision 45)
+++ /trunk/src/CRXHttpRequest.cpp	(revision 46)
@@ -21,21 +21,12 @@
 {
 	/*----------------------------------------------------------------*/
-	Reset ();
 	/*----------------------------------------------------------------*/
 }
 
 void
-CRXHttpRequest::Reset (void)
+CRXHttpRequest::SetHeader (const char * aHeader)
 {
 	/*----------------------------------------------------------------*/
-	ResetMessage ();
-	/*----------------------------------------------------------------*/
-}
-
-void
-CRXHttpRequest::SetHeader (const char * aHttpRequest)
-{
-	/*----------------------------------------------------------------*/
-	SetMessage (aHttpRequest);
+	Set (aHeader);
 	/*----------------------------------------------------------------*/
 }
@@ -47,5 +38,5 @@
 	/*----------------------------------------------------------------*/
 
-	return GetMessage ();
+	return Get ();
 }
 
@@ -66,5 +57,5 @@
 
 	/*----------------------------------------------------------------*/
-	aHttpRequestUrl = GetHeader ().substr (0, mHttpMessage.find ('\r'));
+	aHttpRequestUrl = GetHeader ().substr (0, mHttpHeader.find ('\r'));
 
 	/*----------------------------------------------------------------
@@ -129,6 +120,37 @@
 }
 
-std::string	CRXHttpRequest::GetURL				(void) const { return mUrl; }
-std::string	CRXHttpRequest::GetHost				(void) const { return mHost; }
-int			CRXHttpRequest::GetPort				(void) const { return mPort; }
-std::string	CRXHttpRequest::GetFileExtension	(void) const { return mFileExtension; }
+std::string
+CRXHttpRequest::GetURL (void) const
+{
+	/*----------------------------------------------------------------*/
+	/*----------------------------------------------------------------*/
+
+	return mUrl;
+}
+
+std::string
+CRXHttpRequest::GetHost (void) const
+{
+	/*----------------------------------------------------------------*/
+	/*----------------------------------------------------------------*/
+
+	return mHost;
+}
+
+int
+CRXHttpRequest::GetPort (void) const
+{
+	/*----------------------------------------------------------------*/
+	/*----------------------------------------------------------------*/
+
+	return mPort;
+}
+
+std::string
+CRXHttpRequest::GetFileExtension (void) const
+{
+	/*----------------------------------------------------------------*/
+	/*----------------------------------------------------------------*/
+
+	return mFileExtension;
+}
Index: /trunk/src/CRXHttpResponse.cpp
===================================================================
--- /trunk/src/CRXHttpResponse.cpp	(revision 45)
+++ /trunk/src/CRXHttpResponse.cpp	(revision 46)
@@ -36,63 +36,14 @@
 {
 	/*----------------------------------------------------------------*/
-	ResetMessage ();
-	ResetContent ();
+	Get ().clear ();
+	mContent.clear ();
 	/*----------------------------------------------------------------*/
 }
 
 void
-CRXHttpResponse::ResetContent (void)
+CRXHttpResponse::SetHeader (const char * aHeader)
 {
 	/*----------------------------------------------------------------*/
-	if (mContent.mBody)
-		free (mContent.mBody);
-
-	memset (&mContent, 0x00, sizeof (mContent));
-	/*----------------------------------------------------------------*/
-}
-
-int
-CRXHttpResponse::SetResponseAll (const char	* aHttpResponse,
-								 const int	aResponseLength)
-{
-	int				aResult = 0;
-
-	const char		* aEndOfHeader = NULL;
-	std::string		aHeader;
-
-	int				aHeaderLength = 0;
-
-	/*----------------------------------------------------------------*/
-	if (aResponseLength <= 0)
-		return ERROR_HTTP_RESPONSE_INVALID_LENGTH;
-
-	if (GetHeader ().rfind (CRLF2) == std::string::npos)
-	{
-		aEndOfHeader = strstr (aHttpResponse, CRLF2);
-		if (aEndOfHeader == NULL)
-			return ERROR_HTTP_RESPONSE_INVALID_FORMAT;
-
-		aEndOfHeader += strlen (CRLF2);
-		aHeaderLength = aEndOfHeader - aHttpResponse;
-		aHeader.assign (aHttpResponse, aHeaderLength);
-
-		SetHeader (aHeader.c_str ());
-	}
-
-	aResult = SetContent (aHttpResponse + aHeaderLength, aResponseLength - aHeaderLength);
-	if (aResult)
-	{
-		aResult = ERROR_HTTP_RESPONSE_FAILED_TO_PARSE_CONTENT;
-	}
-	/*----------------------------------------------------------------*/
-
-	return aResult;
-}
-
-void
-CRXHttpResponse::SetHeader (const char * aHttpMessage)
-{
-	/*----------------------------------------------------------------*/
-	SetMessage (aHttpMessage);
+	Set (aHeader);
 	/*----------------------------------------------------------------*/
 }
@@ -104,5 +55,5 @@
 	/*----------------------------------------------------------------*/
 
-	return GetMessage ();
+	return Get ();
 }
 
@@ -164,36 +115,46 @@
 							 const int	aLength)
 {
-	int		aResult = 0;
-
-	char	* aReallocPtr = NULL;
+	int		aResult	= 0;
+	int		aSize	= 0;
+	char	* aChunkedPtr = NULL;
 
 	/*----------------------------------------------------------------*/
-	if (!mIsChunked)
+	/*----------------------------------------------------------------
+	 * 1. check parameter
+	 *----------------------------------------------------------------*/
+	if (aLength < 0)
+		return ERROR_HTTP_RESPONSE_INVALID_LENGTH;
+
+	/*----------------------------------------------------------------
+	 * 2. check content size when is NOT chunked-encoding
+	 *----------------------------------------------------------------*/
+	if (!mIsChunked && mContent.size () >= mContentLength)
+		return 0;
+
+	/*----------------------------------------------------------------
+	 * 3. resize memory and copy
+	 *----------------------------------------------------------------*/
+	aSize = mContent.size ();
+	mContent.resize (aSize + aLength);
+	memcpy (mContent.begin ()._Myptr + aSize, aContent, aLength);
+
+	/*----------------------------------------------------------------
+	 * 4. 
+	 *----------------------------------------------------------------*/
+	aResult = mContent.size ();
+	if (mIsChunked)
 	{
-		if (mContentLength <= mContent.mLength)
-			return aResult;
-
-		if (mContent.mBody == NULL)
+		mContentLength += aLength;
+		aSize = mContent.size ();
+		if ((unsigned int)aSize > strlen (CRLF) + strlen (CRLF2))
 		{
-			mContent.mBody = static_cast<char *> (calloc (mContentLength, 1));
-			if (mContent.mBody == NULL)
+			aChunkedPtr = mContent.begin ()._Myptr + aSize - strlen (CRLF2);
+			if (!strncmp (aChunkedPtr, CRLF2, strlen (CRLF2)))
 			{
-				return ERROR_HTTP_RESPONSE_FAILED_TO_MEMORY_ALLOCATION;
+				for ( ; strncmp (aChunkedPtr--, CRLF, strlen (CRLF)) ; );
+				aResult = strtol (aChunkedPtr, NULL, 16);
 			}
 		}
 	}
-	else
-	{
-		mContentLength += aLength;
-		aReallocPtr = static_cast<char *> (realloc (mContent.mBody, mContentLength));
-		if (aReallocPtr == NULL)
-		{
-			return ERROR_HTTP_RESPONSE_FAILED_TO_MEMORY_ALLOCATION;
-		}
-		mContent.mBody = aReallocPtr;
-	}
-
-	memcpy (mContent.mBody + mContent.mLength, aContent, aLength);
-	mContent.mLength += aLength;
 	/*----------------------------------------------------------------*/
 
@@ -201,6 +162,37 @@
 }
 
-int				CRXHttpResponse::GetStatusCode		(void) const { return mStatusCode; }
-bool			CRXHttpResponse::IsChunked			(void) const { return mIsChunked; }
-int				CRXHttpResponse::GetContentLength	(void) const { return mContentLength; }
-const char *	CRXHttpResponse::GetContentBody		(void) const { return mContent.mBody; }
+int
+CRXHttpResponse::GetStatusCode (void) const
+{
+	/*----------------------------------------------------------------*/
+	/*----------------------------------------------------------------*/
+
+	return mStatusCode;
+}
+
+bool
+CRXHttpResponse::IsChunked (void) const
+{
+	/*----------------------------------------------------------------*/
+	/*----------------------------------------------------------------*/
+
+	return mIsChunked;
+}
+
+int
+CRXHttpResponse::GetContentLength (void) const
+{
+	/*----------------------------------------------------------------*/
+	/*----------------------------------------------------------------*/
+
+	return mContentLength;
+}
+
+const char *
+CRXHttpResponse::GetContentBody (void) const
+{
+	/*----------------------------------------------------------------*/
+	/*----------------------------------------------------------------*/
+
+	return mContent.empty () ? "" : &mContent[0];
+}
Index: /trunk/src/CRXProxy.cpp
===================================================================
--- /trunk/src/CRXProxy.cpp	(revision 45)
+++ /trunk/src/CRXProxy.cpp	(revision 46)
@@ -91,4 +91,5 @@
 
 	std::string	aHttpHeader;
+
 	/*----------------------------------------------------------------*/
 	for (;;)
@@ -116,26 +117,19 @@
 CRXProxy::SendRequest (void)
 {
-	int		aResult	= 0;
-	int		aSize	= mHttpRequest.GetHeader ().length ();
-
-	struct sockaddr_in	aSockName;
-	socklen_t			aSockLen = sizeof (aSockName);
-
-	/*----------------------------------------------------------------*/
-	if (!mServer)
-	{
-		/* connect */
-		aResult = mServer.Connect (mHttpRequest.GetHost (), mHttpRequest.GetPort (), mServerTimeout);
-		if (aResult < 0)
-		{
-			aResult = ERROR_PROXY_FAILED_TO_CONNECT_TO_SERVER;
-			CRX_ADD_SUBCLASS_ERROR (mServer);
-			CRX_ERROR_SET (aResult, "Failed to connect to server <%s>.", mHttpRequest.GetURL ().c_str ());
-			return aResult;
-		}
-	}
-
-	aResult = mServer.Send (mHttpRequest.GetHeader ().c_str (), aSize);
-	if (aResult != aSize)
+	int	aResult	= 0;
+	int	aLength	= mHttpRequest.GetHeader ().length ();
+
+	/*----------------------------------------------------------------*/
+	aResult = mServer.Connect (mHttpRequest.GetHost (), mHttpRequest.GetPort (), mServerTimeout);
+	if (aResult < 0)
+	{
+		aResult = ERROR_PROXY_FAILED_TO_CONNECT_TO_SERVER;
+		CRX_ADD_SUBCLASS_ERROR (mServer);
+		CRX_ERROR_SET (aResult, "Failed to connect to server <%s>.", mHttpRequest.GetURL ().c_str ());
+		return aResult;
+	}
+
+	aResult = mServer.Send (mHttpRequest.GetHeader ().c_str (), aLength);
+	if (aResult != aLength)
 	{
 		CRX_ADD_SUBCLASS_ERROR (mServer);
@@ -150,15 +144,14 @@
 CRXProxy::ReceiveResponse (void)
 {
-	int					aResult			= 0;
-
-	const unsigned int	aBufferSize		= 1024 * 64;
-	char				aBuffer[aBufferSize + 1] = {0x00, };
+	int			aResult = 0;
+	char		aBuffer;
+
+	std::string	aHttpHeader;
+	bool		aRemainHeader = true;
 
 	/*----------------------------------------------------------------*/
 	for (;;)
 	{
-		memset (aBuffer, 0x00, sizeof (aBuffer));
-
-		aResult = mServer.Receive (aBuffer, aBufferSize);
+		aResult = mServer.Receive (&aBuffer, 1);
 		if (aResult < 0)
 		{
@@ -169,10 +162,24 @@
 		}
 
-		aResult = mHttpResponse.SetResponseAll (aBuffer, aResult);
-		if (aResult < 0)
-		{
-			aResult = ERROR_PROXY_FAILED_TO_SET_RESPONSE;
-			CRX_ERROR_SET (aResult, "Failed to set response.");
-			return aResult;
+		if (aRemainHeader)
+		{
+			aHttpHeader += aBuffer;
+			if (aHttpHeader.rfind (CRLF2) != std::string::npos)
+			{
+				mHttpResponse.SetHeader (aHttpHeader.c_str ());
+				aRemainHeader = false;
+			}
+		}
+		else
+		{
+			aResult = mHttpResponse.SetContent (&aBuffer, aResult);
+			if (aResult < 0)
+			{
+				aResult = ERROR_PROXY_FAILED_TO_SET_RESPONSE;
+				CRX_ERROR_SET (aResult, "Failed to set response.");
+				return aResult;
+			}
+			else if (aResult == 0)
+				break;
 		}
 	}
@@ -185,11 +192,10 @@
 CRXProxy::SendResponse (void)
 {
-	int		aResult	= 0;
-	int		aSize	= 0;
-
-	/*----------------------------------------------------------------*/
-	aSize = mHttpResponse.GetHeader ().length ();;
-	aResult = mClient.Send (mHttpResponse.GetHeader ().c_str (), aSize);
-	if (aResult != aSize)
+	int	aResult = 0;
+	int	aLength = 0;
+	/*----------------------------------------------------------------*/
+	aLength = mHttpResponse.GetHeader ().length ();
+	aResult = mClient.Send (mHttpResponse.GetHeader ().c_str (), aLength);
+	if (aResult != aLength)
 	{
 		CRX_ADD_SUBCLASS_ERROR (mClient);
@@ -198,7 +204,7 @@
 	}
 
-	aSize = mHttpResponse.GetContentLength ();
-	aResult = mClient.Send (mHttpResponse.GetContentBody (), aSize);
-	if (aResult != aSize)
+	aLength = mHttpResponse.GetContentLength ();
+	aResult = mClient.Send (mHttpResponse.GetContentBody (), aLength);
+	if (aResult != aLength)
 	{
 		CRX_ADD_SUBCLASS_ERROR (mClient);
Index: /trunk/src/makefile
===================================================================
--- /trunk/src/makefile	(revision 45)
+++ /trunk/src/makefile	(revision 46)
@@ -15,5 +15,5 @@
 FILES			=	\
 					CRXException		\
-					CRXHttpMessage		\
+					CRXHttpHeader		\
 					CRXHttpRequest		\
 					CRXHttpResponse		\
Index: /trunk/windows/cheroxy/cheroxy.vcproj
===================================================================
--- /trunk/windows/cheroxy/cheroxy.vcproj	(revision 45)
+++ /trunk/windows/cheroxy/cheroxy.vcproj	(revision 46)
@@ -160,5 +160,5 @@
 			</File>
 			<File
-				RelativePath="..\..\src\CRXHttpMessage.cpp"
+				RelativePath="..\..\src\CRXHttpHeader.cpp"
 				>
 			</File>
@@ -198,5 +198,5 @@
 			</File>
 			<File
-				RelativePath="..\..\include\CRXHttpMessage.h"
+				RelativePath="..\..\include\CRXHttpHeader.h"
 				>
 			</File>
