//---------------------- CSPResponse.h ------------------------

//*************************************************************
//*****       Copyright ©2002 - 2004 Micronovae Ltd       *****
//*****                All rights reserved                *****
//*************************************************************


#ifndef _CSPRESPONSE
#define _CSPRESPONSE

#include "CSPConf.h"
#include "CSPLib.h"
#include <httpext.h>
#include "CSPCookies.h"
#include "CSPString.h"
#include "CSPWString.h"
#include "CSPTime.h"
#include "CSPBuffer.h"

#pragma warning( disable : 4290 )

class CSPOBJ_CLASS_EXPORT CSPResponse : public CSPObject
{
public:
	bool Buffer;
	CSPSetCookieSet Cookies;
	CSPDateTime Expires;
	CSPString Status;
	CSPString ContentType;


	bool IsClientConnected() const;
	void Clear();
	void AddHeader(const CSPString& strName,const CSPString& strValue);
	bool Write(const CSPString& strText);
	bool Write(const char* pszText);
	bool WideWrite(const CSPWString& wstrText);
	bool WideWrite(const wchar_t* pwszText);
	unsigned long BinaryWrite( const CSPBuffer& Buffer, unsigned long ulSize = 0 );
	unsigned long BinaryWrite( const unsigned char* pData, unsigned long ulSize );
	bool Flush();
	bool Redirect( const CSPString& strURL );

	CSPResponse(LPEXTENSION_CONTROL_BLOCK p_ecb);
	virtual ~CSPResponse();

protected:
	bool bConnectionClosed;
	bool bFirstFlushDone;
	CSPString strAdditionalHeaders;
	CSPString strBuffer;
	const unsigned long ulDefaultBufferSize;
	LPEXTENSION_CONTROL_BLOCK pECB;

	bool Send();
	bool SendAdditionalHeaders();
	void AddCookieHeaders();

private:
	CSPResponse( const CSPResponse& );
	CSPResponse& operator = ( const CSPResponse& );
};

#endif
