Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
platform
active.directory
adsi
adsi.iis-admin
base
com_ole
complus_mts
component_svcs
database
directx
gdi
graphics_mm
internet.client
internet.server
internet.server.isapi-dev
localization
mapi
messaging
msi
mslayerforunicode
multimedia
networking
networking.ipv6
sdk_install
security
shell
telephony.tapi_2
telephony.tapi_3
telephony.tsp
telephony.wte
tools
ui
ui_shell
win_base_svcs
win16
  
 
date: Fri, 9 May 2008 02:37:00 -0700,    group: microsoft.public.platformsdk.internet.server.isapi-dev        back       


Add Header to HTTP Response   
Hello all,

I'm new to ISAPI programming (and IIS). My task is to add a header to the 
http response. I  built a DLL (see code below) that adds a header to the 
response and tested it on my local machine. When I read the headers of the 
response there is no additional header. Do you have any suggestions?

### Code ########################

#include "stdafx.h"
#include "Test3.h"

CWinApp theApp;

CTestFilter theFilter;

CTestFilter::CTestFilter(){}

CTestFilter::~CTestFilter(){}

BOOL CTestFilter::GetFilterVersion(PHTTP_FILTER_VERSION pVer)
{
	CHttpFilter::GetFilterVersion(pVer);
	pVer->dwFlags &= ~SF_NOTIFY_ORDER_MASK;
	pVer->dwFlags |= SF_NOTIFY_SECURE_PORT | SF_NOTIFY_NONSECURE_PORT | 
SF_NOTIFY_SEND_RESPONSE;
	pVer->dwFlags |= SF_NOTIFY_ORDER_HIGH;
	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;
}

DWORD CTestFilter::OnSendResponse(CHttpFilterContext* pfc, 
PHTTP_FILTER_SEND_RESPONSE pSendResponse)
{
	pfc->AddResponseHeaders("Timestamps: XXXXX\r\n", 0);
	return SF_STATUS_REQ_NEXT_NOTIFICATION;
}

### Code ########################

Thanks,
Heinz
date: Fri, 9 May 2008 02:37:00 -0700   author:   Heinz

Re: Add Header to HTTP Response   
On May 9, 2:37 am, Heinz  wrote:
> Hello all,
>
> I'm new to ISAPI programming (and IIS). My task is to add a header to the
> http response. I  built a DLL (see code below) that adds a header to the> response and tested it on my local machine. When I read the headers of the> response there is no additional header. Do you have any suggestions?
>
> ### Code ########################
>
> #include "stdafx.h"
> #include "Test3.h"
>
> CWinApp theApp;
>
> CTestFilter theFilter;
>
> CTestFilter::CTestFilter(){}
>
> CTestFilter::~CTestFilter(){}
>
> BOOL CTestFilter::GetFilterVersion(PHTTP_FILTER_VERSION pVer)
> {
>         CHttpFilter::GetFilterVersion(pVer);
>         pVer->dwFlags &= ~SF_NOTIFY_ORDER_MASK;
>         pVer->dwFlags |= SF_NOTIFY_SECURE_PORT | SF_NOTIFY_NONSECURE_PORT |
> SF_NOTIFY_SEND_RESPONSE;
>         pVer->dwFlags |= SF_NOTIFY_ORDER_HIGH;
>         TCHAR sz[SF_MAX_FILTER_DESC_LEN];
>         ISAPIVERIFY(::LoadString(AfxGetResourceHandle(),IDS_FILTER, sz,
> SF_MAX_FILTER_DESC_LEN));
>         _tcscpy(pVer->lpszFilterDesc, sz);
>         return TRUE;
>
> }
>
> DWORD CTestFilter::OnSendResponse(CHttpFilterContext* pfc,
> PHTTP_FILTER_SEND_RESPONSE pSendResponse)
> {
>         pfc->AddResponseHeaders("Timestamps: XXXXX\r\n", 0);
>         return SF_STATUS_REQ_NEXT_NOTIFICATION;
>
> }
>
> ### Code ########################
>
> Thanks,
> Heinz


AddResponseHeader() works only when it is called before
SF_NOTIFY_SEND_RESPONSE. It is meant to be used from all events prior
to SF_NOTIFY_SEND_RESPONSE that needed to add RESPONSE headers,
without requiring them to listen to SF_NOTIFY_SEND_RESPONSE
(performance implications - from a cacheability-determination
perspective)

Your choices are to either call AddResponseHeader() before that event,
or use AddHeader() inside of SF_NOTIFY_SEND_RESPONSE itself.

Also, the header value cannot have trailing \r\n, or you may
accidentally introduce double \r\n and inadventently terminate other
request headers.


//David
http://w3-4u.blogspot.com
http://blogs.msdn.com/David.Wang
//
date: Fri, 9 May 2008 11:27:39 -0700 (PDT)   author:   David Wang

Re: Add Header to HTTP Response   
Thanks David, I've tried earlier notifications and it works.

As you saw I wanted to use SF_NOTIFY_SEND_RESPONSE. My aim is to add a 
header to the HTTP response as late as it gets. What is the latest point in 
time to add a response header?

Thanks a lot!
Heinz
date: Tue, 13 May 2008 05:51:00 -0700   author:   Heinz

Re: Add Header to HTTP Response   
On May 13, 5:51 am, Heinz  wrote:
> Thanks David, I've tried earlier notifications and it works.
>
> As you saw I wanted to use SF_NOTIFY_SEND_RESPONSE. My aim is to add a
> header to the HTTP response as late as it gets. What is the latest point in
> time to add a response header?
>
> Thanks a lot!
> Heinz


What do you really want to do? The later you add a response header,
the harder it gets. And since response headers are not defined to be
ordered by HTTP RFC, I don't understand why you need it to be as late
as it gets.


//David
http://w3-4u.blogspot.com
http://blogs.msdn.com/David.Wang
//
date: Tue, 13 May 2008 09:41:27 -0700 (PDT)   author:   David Wang

Re: Add Header to HTTP Response   
I have to add a header with a timestamp to the response. It has to be as late 
as it gets because the clients that send the requests need to know how long 
processing takes on the server.

(Of course this is just the first part. The next problem will be how to get 
the incomming timestamp, but this is the next step...)

Regards,
Heinz


"David Wang" wrote:
> 
> What do you really want to do? The later you add a response header,
> the harder it gets. And since response headers are not defined to be
> ordered by HTTP RFC, I don't understand why you need it to be as late
> as it gets.
> 
> 
> //David
> http://w3-4u.blogspot.com
> http://blogs.msdn.com/David.Wang
> //
>
date: Fri, 16 May 2008 01:55:01 -0700   author:   Heinz

Re: Add Header to HTTP Response   
On May 16, 1:55 am, Heinz  wrote:
> I have to add a header with a timestamp to the response. It has to be as late
> as it gets because the clients that send the requests need to know how long
> processing takes on the server.
>
> (Of course this is just the first part. The next problem will be how to get
> the incomming timestamp, but this is the next step...)
>
> Regards,
> Heinz
>
>
>
> "David Wang" wrote:
>
> > What do you really want to do? The later you add a response header,
> > the harder it gets. And since response headers are not defined to be
> > ordered by HTTP RFC, I don't understand why you need it to be as late
> > as it gets.
>
> > //David
> >http://w3-4u.blogspot.com
> >http://blogs.msdn.com/David.Wang
> > //- Hide quoted text -
>
> - Show quoted text -


Add/SetHeader in SF_NOTIFY_SEND_RESPONSE is what you want. There are
other processing steps after that event, but you won't be able to
[easily] modify the response by that point.

It sounds like what you really want is to log the time taken when it
reaches SF_NOTIFY_END_OF_REQUEST, but by that time, the response has
left IIS so you have no way to change the headers. You could choose to
buffer the response and send it at SF_NOTIFY_END_OF_REQUEST, but that
makes the response synchronous and have bad performance consequences.

In other words, the more accurate of a value you want returned on the
request of interest, the more intrusive and damaging it becomes.

It is more accurate and better performing for the timing details to be
logged on the server, and a secondary process goes through the logs in
near-real-time, on-demand.

In other words, you just log the timing in a log file, and another
request to retrieve and process from that log file for the exact
request that was just sent.


//David
http://w3-4u.blogspot.com
http://blogs.msdn.com/David.Wang
//
date: Fri, 16 May 2008 16:19:08 -0700 (PDT)   author:   David Wang

Re: Add Header to HTTP Response   
Thanks for your answer David. It was very helpful. I use addheader now (By 
the way sorry for the late reply, i was on vacation).

Please let me ask another question: At the moment I'm facing a problem 
concerning the GetHeader function. It try to use it like this:

char buffer[256];
DWORD buffSize = sizeof(buffer);
if(abc->GetHeader(pfc->m_pFC, "Timestamp", buffer, &buffSize))
{ ... }

The Problem is it always fails.

GetLastError returns 1413 (ERROR_INVALID_INDEX).

Do you have any suggestions?
Thanks!


"David Wang" wrote:

> On May 16, 1:55 am, Heinz  wrote:
> > I have to add a header with a timestamp to the response. It has to be as late
> > as it gets because the clients that send the requests need to know how long
> > processing takes on the server.
> >
> > (Of course this is just the first part. The next problem will be how to get
> > the incomming timestamp, but this is the next step...)
> >
> > Regards,
> > Heinz
> >
> >
> >
> > "David Wang" wrote:
> >
> > > What do you really want to do? The later you add a response header,
> > > the harder it gets. And since response headers are not defined to be
> > > ordered by HTTP RFC, I don't understand why you need it to be as late
> > > as it gets.
> >
> > > //David
> > >http://w3-4u.blogspot.com
> > >http://blogs.msdn.com/David.Wang
> > > //- Hide quoted text -
> >
> > - Show quoted text -
> 
> 
> Add/SetHeader in SF_NOTIFY_SEND_RESPONSE is what you want. There are
> other processing steps after that event, but you won't be able to
> [easily] modify the response by that point.
> 
> It sounds like what you really want is to log the time taken when it
> reaches SF_NOTIFY_END_OF_REQUEST, but by that time, the response has
> left IIS so you have no way to change the headers. You could choose to
> buffer the response and send it at SF_NOTIFY_END_OF_REQUEST, but that
> makes the response synchronous and have bad performance consequences.
> 
> In other words, the more accurate of a value you want returned on the
> request of interest, the more intrusive and damaging it becomes.
> 
> It is more accurate and better performing for the timing details to be
> logged on the server, and a secondary process goes through the logs in
> near-real-time, on-demand.
> 
> In other words, you just log the timing in a log file, and another
> request to retrieve and process from that log file for the exact
> request that was just sent.
> 
> 
> //David
> http://w3-4u.blogspot.com
> http://blogs.msdn.com/David.Wang
> //
>
date: Fri, 30 May 2008 08:07:01 -0700   author:   Heinz

Re: Add Header to HTTP Response   
When calling Add/Get/Set header, the header name must have the
trailing colon. See documentation:

http://msdn.microsoft.com/en-us/library/ms525034(VS.85).aspx


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




On May 30, 8:07 am, Heinz  wrote:
> Thanks for your answer David. It was very helpful. I use addheader now (By> the way sorry for the late reply, i was on vacation).
>
> Please let me ask another question: At the moment I'm facing a problem
> concerning the GetHeader function. It try to use it like this:
>
> char buffer[256];
> DWORD buffSize = sizeof(buffer);
> if(abc->GetHeader(pfc->m_pFC, "Timestamp", buffer, &buffSize))
> { ... }
>
> The Problem is it always fails.
>
> GetLastError returns 1413 (ERROR_INVALID_INDEX).
>
> Do you have any suggestions?
> Thanks!
>
>
>
> "David Wang" wrote:
> > On May 16, 1:55 am, Heinz  wrote:
> > > I have to add a header with a timestamp to the response. It has to be as late
> > > as it gets because the clients that send the requests need to know how long
> > > processing takes on the server.
>
> > > (Of course this is just the first part. The next problem will be how to get
> > > the incomming timestamp, but this is the next step...)
>
> > > Regards,
> > > Heinz
>
> > > "David Wang" wrote:
>
> > > > What do you really want to do? The later you add a response header,
> > > > the harder it gets. And since response headers are not defined to be> > > > ordered by HTTP RFC, I don't understand why you need it to be as late
> > > > as it gets.
>
> > > > //David
> > > >http://w3-4u.blogspot.com
> > > >http://blogs.msdn.com/David.Wang
> > > > //- Hide quoted text -
>
> > > - Show quoted text -
>
> > Add/SetHeader in SF_NOTIFY_SEND_RESPONSE is what you want. There are
> > other processing steps after that event, but you won't be able to
> > [easily] modify the response by that point.
>
> > It sounds like what you really want is to log the time taken when it
> > reaches SF_NOTIFY_END_OF_REQUEST, but by that time, the response has
> > left IIS so you have no way to change the headers. You could choose to
> > buffer the response and send it at SF_NOTIFY_END_OF_REQUEST, but that
> > makes the response synchronous and have bad performance consequences.
>
> > In other words, the more accurate of a value you want returned on the
> > request of interest, the more intrusive and damaging it becomes.
>
> > It is more accurate and better performing for the timing details to be
> > logged on the server, and a secondary process goes through the logs in
> > near-real-time, on-demand.
>
> > In other words, you just log the timing in a log file, and another
> > request to retrieve and process from that log file for the exact
> > request that was just sent.
>
> > //David
> >http://w3-4u.blogspot.com
> >http://blogs.msdn.com/David.Wang
> > //- Hide quoted text -
>
> - Show quoted text -
date: Fri, 30 May 2008 10:53:01 -0700 (PDT)   author:   David Wang

Re: Add Header to HTTP Response   
Tanks very much David. Everything works now :-) but let me ask one more 
question because I'm a little bit confused now: There seem to be two ways to 
develop ISAPI-Filters. I developed mine with MFC. Is this outdated or what is 
the difference? 

Heinz


"David Wang" wrote:

> When calling Add/Get/Set header, the header name must have the
> trailing colon. See documentation:
> 
> http://msdn.microsoft.com/en-us/library/ms525034(VS.85).aspx
> 
> 
> //David
> http://w3-4u.blogspot.com
> http://blogs.msdn.com/David.Wang
> //
> 
>
date: Fri, 6 Jun 2008 04:01:01 -0700   author:   Heinz

Re: Add Header to HTTP Response   
On Jun 6, 4:01 am, Heinz  wrote:
> Tanks very much David. Everything works now :-) but let me ask one more
> question because I'm a little bit confused now: There seem to be two ways to
> develop ISAPI-Filters. I developed mine with MFC. Is this outdated or what is
> the difference?
>
> Heinz
>
>
>
> "David Wang" wrote:
> > When calling Add/Get/Set header, the header name must have the
> > trailing colon. See documentation:
>
> >http://msdn.microsoft.com/en-us/library/ms525034(VS.85).aspx
>
> > //David
> >http://w3-4u.blogspot.com
> >http://blogs.msdn.com/David.Wang
> > //- Hide quoted text -
>
> - Show quoted text -


MFC ISAPI "Framework" involves more overhead, and if you are not using
any of the ISAPI features, then it is unnecessary dependency that I've
seen get people into trouble.

In short, I always write directly to pure ISAPI. Avoids all the
complications.


//David
http://w3-4u.blogspot.com
http://blogs.msdn.com/David.Wang
//
date: Fri, 6 Jun 2008 23:18:36 -0700 (PDT)   author:   David Wang

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us