void AddHeader( CHttpServerContext* pCtxt, LPCTSTR pszString ) const;
Parameters
pCtxt
A pointer to a CHttpServerContext object.
pszString
A pointer to a string.
Remarks
Call this member function to add a header to the response before the response is sent to the server. Use AddHeader to append your own headers to those the server supplies when it receives CHttpServerContext::ServerSupportFunction HSE_REQ_SEND_RESPONSE_HEADERS. The extra header provides the client with more information.
For example, call AddHeader to specify your own "content-type," then call it to specify an encoding, and then call it once more to insert the "content-length" header. After you have called AddHeader as many times as you need, use << to stream your output until you are done.
Note Once you put data in the HTML stream in the server context, do not call AddHeader again. If you do, your HTML stream will not work properly.
Example
The following code demonstrates how to use AddHeader to add a customer header. In this instance customer headers represents a cookie. szCookie is supplied in the request in following fashion:
http://server/scripts/MfcCookie.dll?SetCookie?cookie=Hello
BEGIN_PARSE_MAP(CMfcCookieExtension, CHttpServer)
...
ON_PARSE_COMMAND(SetCookie, CMfcCookieExtension, ITS_PSTR)
ON_PARSE_COMMAND_PARAMS ("cookie")
...
END_PARSE_MAP(CMfcCookieExtension)
void CMfcCookieExtension::SetCookie(CHttpServerContext * pCtxt,
LPCTSTR szCookie)
{
char szHeader [256];
StartContent(pCtxt);
wsprintf (szHeader, "Set-Cookie: LeonBrCookie=%s;"
" expires=Friday, 22-May-99 13:00:00 GMT; path=/;\r\n", szCookie);
AddHeader(pCtxt, szHeader);
AddHeader(pCtxt, "Expires: 0\r\n");
*pCtxt <<"Cookie name/value: <b>"<< szHeader <<"</b> is set <br>";
EndContent(pCtxt);
}
Here is an example of a function that creates an on-the-fly web-page:
void CHelloExtension::Default(CHttpServerContext* pCtxt)
{
AddHeader(pCtxt, "Content-type = text/plain\r\n");
(*pCtxt) << "Hello world!\r\n";
}
CHttpServer Overview | Class Members | Hierarchy Chart
See Also CHttpServerContext, CHttpServerContext::ServerSupportFunction