This documentation is archived and is not being maintained.


Call this method to get the value of a server variable from the HTTP server context object.

BOOL GetServerVariable(
   LPCSTR pszVariableName,
   LPSTR pvBuffer,
   DWORD* pdwSize 



The name of the server variable.


A caller-allocated buffer used to hold the value of the server variable on completion of the function.


On entry, the size of the buffer in bytes. On exit, the DWORD contains the number of bytes transferred or available to be transferred into the buffer (including the null-terminating byte).

Returns TRUE on success, and FALSE on failure. Call GetLastError to get extended error information.

This method is equivalent to EXTENSION_CONTROL_BLOCK::GetServerVariable.

[ tag_name(name="GetServerVariable") ]
HTTP_CODE OnGetServerVariable(char* szServerVariable)
    // This replacement method will get the server
    // variable specified in the SRF file.

    BOOL bRet = TRUE;
    CHeapPtr<char> spBuf;

    char szBuf[256];
    char* pszBuf = szBuf;
    DWORD dwLen = sizeof(szBuf) - 1;

    bRet = m_spServerContext->GetServerVariable(

    if (!bRet && dwLen >= sizeof(szBuf))
        // If the buffer was too small, allocate a buffer of
        // adequate size.

        if (!spBuf.AllocateBytes(dwLen+1))
            pszBuf = spBuf;

            // Try again to get the server variable.
            bRet = m_spServerContext->GetServerVariable(
                                       szServerVariable, pszBuf, &dwLen);
            if (!bRet)
                // output message
                m_HttpResponse << "Failed to get server variable : "
                               << szServerVariable;

    if (bRet)
        pszBuf[dwLen] = '\0';
        m_HttpResponse << pszBuf;
    if (bRet)
        return HTTP_SUCCESS;

    return AtlsHttpError(500, ISE_SUBERR_OUTOFMEM);