GetHeader command for current domain?

GetHeader command for current domain?

am 10.01.2007 11:02:55 von buzz

Hi all
am trying to write a redirection filter. in c++ with MFC

here is some code ...
DWORD CRedirectorFilter::OnPreprocHeaders(CHttpFilterContext* pCtxt,
PHTTP_FILTER_PREPROC_HEADERS pHeaderInfo)
{
if (true == ReloadIniFileNeeded())
{
if (false == LoadMap())
{
return SF_STATUS_REQ_NEXT_NOTIFICATION;
}
}
char buffer[256];
DWORD buffSize = sizeof(buffer);
BOOL bHeader = pHeaderInfo->GetHeader(pCtxt->m_pFC, "url", buffer,
&buffSize);
CString urlString(buffer);
urlString.MakeLower(); // for this exercise
CString baseUrl = GetWebRoot(urlString);
igor_map::iterator iter = domain_map.find(baseUrl);
DWORD dwRet = SF_STATUS_REQ_NEXT_NOTIFICATION;


my hosts file is set to forward all requests for

www.somewhere.com to the ip of the PC...this happens correctly

however

the problem i am having from my XP box is that when thi line of code
runs

BOOL bHeader = pHeaderInfo->GetHeader(pCtxt->m_pFC, "url", buffer,
&buffSize);

the buffer does not contain "www.somewhere.com", it just holds "/"

how can i ask IIS to tell me which domain was requested?

regards and thanks

Buzz

Re: GetHeader command for current domain?

am 11.01.2007 05:25:43 von David Wang

Are you sure that the client sent "www.somewhere.com" in the URL?

I believe the client sent www.somewhere.com as the Host header, hence
you have to call GetHeader("Host:") to retrieve it.


//David
http://w3-4u.blogspot.com
http://blogs.msdn.com/David.Wang
//


buzz wrote:
> Hi all
> am trying to write a redirection filter. in c++ with MFC
>
> here is some code ...
> DWORD CRedirectorFilter::OnPreprocHeaders(CHttpFilterContext* pCtxt,
> PHTTP_FILTER_PREPROC_HEADERS pHeaderInfo)
> {
> if (true == ReloadIniFileNeeded())
> {
> if (false == LoadMap())
> {
> return SF_STATUS_REQ_NEXT_NOTIFICATION;
> }
> }
> char buffer[256];
> DWORD buffSize = sizeof(buffer);
> BOOL bHeader = pHeaderInfo->GetHeader(pCtxt->m_pFC, "url", buffer,
> &buffSize);
> CString urlString(buffer);
> urlString.MakeLower(); // for this exercise
> CString baseUrl = GetWebRoot(urlString);
> igor_map::iterator iter = domain_map.find(baseUrl);
> DWORD dwRet = SF_STATUS_REQ_NEXT_NOTIFICATION;
>
>
> my hosts file is set to forward all requests for
>
> www.somewhere.com to the ip of the PC...this happens correctly
>
> however
>
> the problem i am having from my XP box is that when thi line of code
> runs
>
> BOOL bHeader = pHeaderInfo->GetHeader(pCtxt->m_pFC, "url", buffer,
> &buffSize);
>
> the buffer does not contain "www.somewhere.com", it just holds "/"
>
> how can i ask IIS to tell me which domain was requested?
>
> regards and thanks
>
> Buzz

Re: GetHeader command for current domain?

am 14.01.2007 03:49:42 von buzz

David Wang wrote:
> Are you sure that the client sent "www.somewhere.com" in the URL?
>
> I believe the client sent www.somewhere.com as the Host header, hence
> you have to call GetHeader("Host:") to retrieve it.
>
>

thanks David

I tried GetHeader("Host:") as you suggested, but i still get "/"

DWORD CRedirectorFilter::OnPreprocHeaders(CHttpFilterContext* pCtxt,
PHTTP_FILTER_PREPROC_HEADERS pHeaderInfo)
{

char buffer[256];
DWORD buffSize = sizeof(buffer);
BOOL bHeader = pHeaderInfo->GetHeader(pCtxt->m_pFC, "Host:", buffer,
&buffSize);


The break point i have set gets hit and i can examine the variables and
so on.



am i missing something?


regards

Buzz

Re: GetHeader command for current domain?

am 15.01.2007 01:27:36 von David Wang

The values you are looking can only be retrieved with the "Host:" and
"url" headers in OnPreprocHeaders. If you are not getting what you
expect, then you need to start looking at the raw bytes of the request
with tools like Network Sniffers.

Or you can use a tool like WFetch to simulate an expected request and
verify your code's behavioral correctness.

FYI: It is not possible to server-side redirect requests between IIS
websites from OnPreprocHeaders. Sending 30X client-side redirects, or
if the logical websites are all hosted within the same IIS website via
Host Headers, would work to "redirect", but I am not certain what
exactly you are trying to accomplish. Can you please describe exactly
what you want to achieve.


//David
http://w3-4u.blogspot.com
http://blogs.msdn.com/David.Wang
//


buzz wrote:
> David Wang wrote:
> > Are you sure that the client sent "www.somewhere.com" in the URL?
> >
> > I believe the client sent www.somewhere.com as the Host header, hence
> > you have to call GetHeader("Host:") to retrieve it.
> >
> >
>
> thanks David
>
> I tried GetHeader("Host:") as you suggested, but i still get "/"
>
> DWORD CRedirectorFilter::OnPreprocHeaders(CHttpFilterContext* pCtxt,
> PHTTP_FILTER_PREPROC_HEADERS pHeaderInfo)
> {
>
> char buffer[256];
> DWORD buffSize = sizeof(buffer);
> BOOL bHeader = pHeaderInfo->GetHeader(pCtxt->m_pFC, "Host:", buffer,
> &buffSize);
>
>
> The break point i have set gets hit and i can examine the variables and
> so on.
>
>
>
> am i missing something?
>
>
> regards
>
> Buzz

Re: GetHeader command for current domain?

am 15.01.2007 03:10:26 von buzz

thanks david, it turns out IIS was misbehaving so i uninstalled it,
deleted the remains, and reinstalled
and whatya know - the code worked :)

very happy

thanks for your help

Buzz