dropContentLengthGet (v 0.7 beta) : source code step by step


  This source code is the main file "CDropContentLengthGet.cpp".


#include "stdafx.h"
#include "dropContentLengthGet.h"

CWinApp theApp;

CDropContentLengthGetFilter theFilter;

CDropContentLengthGetFilter::CDropContentLengthGetFilter() { }
CDropContentLengthGetFilter::~CDropContentLengthGetFilter() { }

BOOL CDropContentLengthGetFilter::GetFilterVersion(PHTTP_FILTER_VERSION pVer)
{
	CHttpFilter::GetFilterVersion(pVer);

	pVer->dwFlags &= ~SF_NOTIFY_ORDER_MASK;
	pVer->dwFlags |= SF_NOTIFY_ORDER_LOW | SF_NOTIFY_SECURE_PORT | SF_NOTIFY_NONSECURE_PORT | SF_NOTIFY_PREPROC_HEADERS;

	TCHAR sz[SF_MAX_FILTER_DESC_LEN+1];
	ISAPIVERIFY(::LoadString(AfxGetResourceHandle(), IDS_FILTER, sz, SF_MAX_FILTER_DESC_LEN));
	_tcscpy(pVer->lpszFilterDesc, sz);
	return TRUE;
}
This part is generated by the VC++ ISAPI wizard, nothing here is specific to the filter.
DWORD CDropContentLengthGetFilter::OnPreprocHeaders(CHttpFilterContext* pCtxt, PHTTP_FILTER_PREPROC_HEADERS pHeaderInfo)
{
	char strValue[32];
	DWORD szStrValue;
The "OnPreprocHeaders" method is executed before IIS processes the headers coming from client browser. At this point, headers can be changed removed etc... This is the heart of this filter. Local variables permit to retrieve values from headers.
	szStrValue = sizeof strValue;
        if (!pHeaderInfo->GetHeader((_HTTP_FILTER_CONTEXT *) pCtxt->m_pFC, "Content-Length:", strValue, &szStrValue))
		return SF_STATUS_REQ_NEXT_NOTIFICATION;
Firstly, if the "Content-Length:" header is not present, the filter has nothing to do. The next notification is then triggered by IIS.
	szStrValue = sizeof strValue;
	if (!pHeaderInfo->GetHeader(pCtxt->m_pFC, "method", strValue, &szStrValue))
		return SF_STATUS_REQ_ERROR;
If no method is found (GET, POST etc...), an error is returned as this can be considered as an error.
	if (strcmp (strValue, "GET") == 0)
		pHeaderInfo->SetHeader(pCtxt->m_pFC, "Content-Length:", NULL);
	return SF_STATUS_REQ_NEXT_NOTIFICATION;
}
If this is the "GET" method, then the "Content-Length:" header is simply removed. That way, this is as if browser has not send the header. The next notification is the triggered by IIS.
// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CDropContentLengthGetFilter, CHttpFilter)
	//{{AFX_MSG_MAP(CDropContentLengthGetFilter)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif	// 0
This part is generated by the wizard, and ends the source code. Quite simple no ?