当前位置: 首页>>代码示例>>C++>>正文


C++ HttpReq::getHeaderLen方法代码示例

本文整理汇总了C++中HttpReq::getHeaderLen方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpReq::getHeaderLen方法的具体用法?C++ HttpReq::getHeaderLen怎么用?C++ HttpReq::getHeaderLen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpReq的用法示例。


在下文中一共展示了HttpReq::getHeaderLen方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: connectSSL

int ProxyConn::connectSSL()
{
    if (!m_ssl.getSSL())
    {
        m_ssl.setSSL(getSslConn());
        if (!m_ssl.getSSL())
            return LS_FAIL;
        m_ssl.setfd(getfd());
        HttpReq *pReq = getConnector()->getHttpSession()->getReq();
        char *pHostName;
        int hostLen = pReq->getNewHostLen();
        if (hostLen > 0)
            pHostName = (char *)pReq->getNewHost();
        else
        {
            pHostName = (char *)pReq->getHeader(HttpHeader::H_HOST);
            hostLen = pReq->getHeaderLen(HttpHeader::H_HOST);
        }
        if (pHostName)
        {
            char ch = *(pHostName + hostLen);
            *(pHostName + hostLen) = 0;
            m_ssl.setTlsExtHostName(pHostName);
            *(pHostName + hostLen) = ch;
        }
    }
    int ret = m_ssl.connect();
    switch (ret)
    {
    case 0:
        setSSLAgain();
        break;
    case 1:
        LS_DBG_L(this, "[SSL] connected!");
        break;
    default:
        if (errno == EIO)
            LS_DBG_L(this, "SSL_connect() failed!: %s ", SslError().what());
        break;
    }

    return ret;
}
开发者ID:52M,项目名称:openlitespeed,代码行数:43,代码来源:proxyconn.cpp

示例2: getSubstValue

int RequestVars::getSubstValue( const SubstItem * pItem, HttpSession *pSession,
                        char * &pValue, int bufLen )
{
    HttpReq * pReq = pSession->getReq();
    int type = pItem->getType();
    int i;
    if ( type < REF_STRING )
    {
        pValue = (char *)pReq->getHeader( type );
        if ( *pValue )
            return pReq->getHeaderLen( type );
        else
            return 0;
    }

    switch( type )
    {
    case REF_STRING:
        pValue = (char *)pItem->getStr()->c_str();
        return pItem->getStr()->len();
        
    case REF_ENV:
        pValue = (char *)RequestVars::getEnv( pSession, pItem->getStr()->c_str(), 
                    pItem->getStr()->len(), i );
        if ( !pValue )
        {
            i = 0;
        }
        return i;
    case REF_HTTP_HEADER:
        pValue = (char *)pReq->getHeader( pItem->getStr()->c_str(),
                        pItem->getStr()->len(), i );
        if ( !pValue )
            i = 0;
        return i;
    default:
        return RequestVars::getReqVar( pSession, type, pValue, bufLen );
    }
    return 0;
}
开发者ID:diegomontoya,项目名称:openlitespeed,代码行数:40,代码来源:requestvars.cpp

示例3: getSubstValue

int RewriteEngine::getSubstValue( const RewriteSubstItem * pItem, HttpConnection *pConn,
                        char * &pValue, int bufLen )
{
    HttpReq * pReq = pConn->getReq();
    int type = pItem->getType();
    int i;
    if ( type < REF_STRING )
    {
        pValue = (char *)pReq->getHeader( type );
        if ( *pValue )
            return pReq->getHeaderLen( type );
        else
            return 0;
    }

/*
    if ( type >= REF_TIME )
    {
        time_t t = time(NULL);
        struct tm *tm = localtime(&t);
        switch( type )
        {
        case REF_TIME:
            i = snprintf( pValue, bufLen,
                        "%04d%02d%02d%02d%02d%02d", tm->tm_year + 1900,
                        tm->tm_mon+1, tm->tm_mday,
                        tm->tm_hour, tm->tm_min, tm->tm_sec);
            break;
        case REF_TIME_YEAR:
            i = snprintf( pValue, bufLen, "%04d", tm->tm_year + 1900);
            break;
        case REF_TIME_MON:
            i = snprintf( pValue, bufLen, "%02d", tm->tm_mon+1 );
            break;
        case REF_TIME_DAY:
            i = snprintf( pValue, bufLen, "%02d", tm->tm_mday);
            break;
        case REF_TIME_HOUR:
            i = snprintf( pValue, bufLen, "%02d", tm->tm_hour);
            break;
        case REF_TIME_MIN:
            i = snprintf( pValue, bufLen, "%02d", tm->tm_min);
            break;
        case REF_TIME_SEC:
            i = snprintf( pValue, bufLen, "%02d", tm->tm_sec);
            break;
        case REF_TIME_WDAY:
            i = snprintf( pValue, bufLen, "%d", tm->tm_wday);
            break;
        default:
            return 0;
        }
        return i;
    }
*/
    switch( type )
    {
    case REF_STRING:
        pValue = (char *)pItem->getStr()->c_str();
        return pItem->getStr()->len();
    case REF_MAP:
        {
            MapRefItem * pRef = pItem->getMapRef();
            int len = 1024;
            char achBuf[1024];
            if ( buildString( pRef->getKeyFormat(), pConn, achBuf, len ) == NULL )
                return 0;
            if ( (len = pRef->getMap()->lookup( achBuf, len, pValue, bufLen )) == -1 )
            {
                if ( pRef->getDefaultFormat() )
                {
                    if ( buildString( pRef->getDefaultFormat(), pConn,
                                    pValue, bufLen ) == NULL )
                        return 0;
                    len = bufLen;
                }        
                else
                    len = 0;
            }
            return len;
        }
        break;             
    case REF_RULE_SUBSTR:
        return getSubstr( m_pSourceURL, m_ruleVec, m_ruleMatches, pItem->getIndex(),
                    pValue, m_flag & RULE_FLAG_BR_ESCAPE );
    case REF_COND_SUBSTR:
        return getSubstr( m_pCondBuf, m_condVec, m_condMatches, pItem->getIndex(),
                    pValue, m_flag & RULE_FLAG_BR_ESCAPE );
    case REF_ENV:
        pValue = (char *)RequestVars::getEnv( pConn, pItem->getStr()->c_str(), 
                    pItem->getStr()->len(), i );
        if ( !pValue )
        {
            i = 0;
        }
        return i;
    case REF_HTTP_HEADER:
        pValue = (char *)pReq->getHeader( pItem->getStr()->c_str(),
                        pItem->getStr()->len(), i );
        if ( !pValue )
//.........这里部分代码省略.........
开发者ID:lsmichael,项目名称:openlitespeed,代码行数:101,代码来源:rewriteengine.cpp

示例4: getReqVar

int RequestVars::getReqVar( HttpSession *pSession, int type, char * &pValue, int bufLen)
{
    HttpReq * pReq = pSession->getReq();
    int i;
    char *p;
    if ( type < REF_STRING )
    {
        pValue = (char *)pReq->getHeader( type );
        if ( *pValue )
            return pReq->getHeaderLen( type );
        else
            return 0;
    }
    switch( type )
    {
    case REF_REMOTE_HOST:
        //FIXME: use remote addr for now
    case REF_REMOTE_ADDR:
        pValue = (char *)pSession->getPeerAddrString();
        return pSession->getPeerAddrStrLen();
    case REF_REMOTE_PORT:
        return snprintf( pValue, bufLen, "%hu", pSession->getRemotePort() );
    case REF_REMOTE_USER:
        pValue = (char *)pReq->getAuthUser();
        return strlen( pValue );
    case REF_REMOTE_IDENT:
        //do not support;
        return 0;
    case REF_REQ_METHOD:
        i = pReq->getMethod();
        strcpy(pValue, HttpMethod::get( i ) );
        return HttpMethod::getLen( i );
    case REF_QUERY_STRING:
        pValue = (char *)pReq->getQueryString();
        return pReq->getQueryStringLen();
    case REF_AUTH_TYPE:
        //FIXME: hard code for now
        strncpy( pValue, "Basic", 6 );
        return 5;
    case REF_REQUST_FN:
    case REF_SCRIPTFILENAME:
    case REF_SCRIPT_BASENAME:
    case REF_REQ_BASENAME: 
    {
        const AutoStr2 * psTemp = pReq->getRealPath();
        if ( psTemp )
        {
            if (( type == REF_SCRIPT_BASENAME )||
                ( type == REF_REQ_BASENAME ))
            {
                const char * pEnd = psTemp->c_str() + psTemp->len();
                pValue = (char *)pEnd;
                while( pValue[-1] != '/' )
                    --pValue;
                return pEnd - pValue;
            }
            pValue = (char *)psTemp->c_str();
            return psTemp->len();
        }
        else
            return 0;
    }
    case REF_SCRIPT_UID:
    case REF_SCRIPT_GID:
    case REF_SCRIPT_USERNAME:
    case REF_SCRIPT_GRPNAME:
    case REF_SCRIPT_MODE:
    {
        const AutoStr2 * psTemp = pReq->getRealPath();
        if ( psTemp )
        {
            struct stat& st = pReq->getFileStat();
            if ( type == REF_SCRIPT_UID )
            {
                return snprintf( pValue, bufLen, "%d", st.st_uid );
            }
            else if ( type == REF_SCRIPT_GID )
            {
                return snprintf( pValue, bufLen, "%d", st.st_gid );
            }
            else if ( type == REF_SCRIPT_MODE )
            {
                return snprintf( pValue, bufLen, "%o", st.st_mode );
            }
            else if ( type == REF_SCRIPT_USERNAME )
            {
                struct passwd * pw = getpwuid( st.st_uid );
                if ( pw )
                    return snprintf( pValue, bufLen, "%s", pw->pw_name );
            }
            else
            {
                struct group * gr = getgrgid( st.st_gid );
                if ( gr )
                    return snprintf( pValue, bufLen, "%s", gr->gr_name );
            }
        }
        return 0;
    }
    case REF_PATH_INFO:
//.........这里部分代码省略.........
开发者ID:diegomontoya,项目名称:openlitespeed,代码行数:101,代码来源:requestvars.cpp

示例5: log

void AccessLog::log( HttpConnection* pConn )
{
    int  n;
    HttpReq*  pReq  = pConn->getReq();
    HttpResp* pResp = pConn->getResp();
    const char * pUser = pReq->getAuthUser();
    long contentWritten = pResp->getBodySent();
    const ClientInfo * pInfo = pConn->getClientInfo();
    const char * pAddr = pInfo->getHostName();
    pResp->needLogAccess( 0 );
    if ( m_iPipedLog )
    {
        if ( !m_pManager )
            return;
        m_pAppender = m_pManager->getAppender();
        if ( !m_pAppender )
            return;
    }
    
    if ( m_pCustomFormat )
        return customLog( pConn );
    
    if (( pAddr )&&( *pAddr ))
    {
        n = pInfo->getHostNameLen();
    }
    else
    {
        pAddr = pInfo->getAddrString();
        n = pInfo->getAddrStrLen();
    }
    m_buf.appendNoCheck( pAddr, n );
    if ( ! *pUser )
    {
        m_buf.appendNoCheck( " - - ", 5 );
    }
    else
    {
        n = safe_snprintf( m_buf.end(), 70, " - \"%s\" ", pUser );
        m_buf.used( n );
    }

    DateTime::getLogTime( pConn->getReqTime(), m_buf.end() );
    m_buf.used( 30 );
    n = pReq->getOrgReqLineLen();
    char * pOrgReqLine = (char *)pReq->getOrgReqLine();
    if ( pReq->getVersion() == HTTP_1_0 )
        *(pOrgReqLine + n - 1) = '0';
    if (( n > 4096 )||( m_buf.available() < 100 + n ))
    {
        flush();
        m_pAppender->append( pOrgReqLine, n );
    }
    else
        m_buf.appendNoCheck(pOrgReqLine, n );
    m_buf.append( '"' );
    m_buf.appendNoCheck(
        HttpStatusCode::getCodeString( pReq->getStatusCode() ), 5 );
    if ( contentWritten == 0 )
    {
        m_buf.append( '-' );
    }
    else
    {
        n = safe_snprintf( m_buf.end(), 20, "%ld", contentWritten );
        m_buf.used( n );
    }
    if ( getAccessLogHeader() & LOG_REFERER )
    {
        m_buf.append( ' ' );
        appendStr( pReq->getHeader( HttpHeader::H_REFERER ),
                pReq->getHeaderLen( HttpHeader::H_REFERER ));
    }
    if ( getAccessLogHeader() & LOG_USERAGENT )
    {
        m_buf.append( ' ' );
        appendStr( pReq->getHeader( HttpHeader::H_USERAGENT),
                pReq->getHeaderLen( HttpHeader::H_USERAGENT) );
    }
    if ( getAccessLogHeader() & LOG_VHOST )
    {
        m_buf.append( ' ' );
        appendStr( pReq->getHeader( HttpHeader::H_HOST ),
                pReq->getHeaderLen( HttpHeader::H_HOST ) );
    }
    m_buf.append( '\n' );
    if (( m_buf.available() < MAX_LOG_LINE_LEN )
        ||!asyncAccessLog() )
    {
        flush();
    }
}
开发者ID:DSpeichert,项目名称:OpenLiteSpeed,代码行数:92,代码来源:accesslog.cpp

示例6: sendReqHeader

int ProxyConn::sendReqHeader()
{
    m_iovec.clear();
    HttpSession *pSession = getConnector()->getHttpSession();
    HttpReq *pReq = pSession->getReq();
    //remove the trailing "\r\n" before adding our headers
    const char *pBegin = pReq->getOrgReqLine();
    m_iTotalPending = pReq->getHttpHeaderLen();
    int newReqLineLen = 0;
    int headerLen = 17;
    char *pExtraHeader = &m_extraHeader[23];
    const char *pForward = pReq->getHeader(HttpHeader::H_X_FORWARDED_FOR);
    int len;
    if (*pForward != '\0')
    {
        len = pReq->getHeaderLen(HttpHeader::H_X_FORWARDED_FOR);
        if (len > 160)
            len = 160;
        memmove(&pExtraHeader[headerLen], pForward, len);
        headerLen += len;
        pExtraHeader[headerLen++] = ',';

    }
    //add "X-Forwarded-For" header
    memmove(&pExtraHeader[headerLen], pSession->getPeerAddrString(),
            pSession->getPeerAddrStrLen());
    headerLen += pSession->getPeerAddrStrLen();
    pExtraHeader[headerLen++] = '\r';
    pExtraHeader[headerLen++] = '\n';

#if 1       //always set "Accept-Encoding" header to "gzip"
    char *pAE = (char *)pReq->getHeader(HttpHeader::H_ACC_ENCODING);
    if (*pAE)
    {
        int len = pReq->getHeaderLen(HttpHeader::H_ACC_ENCODING);
        if (len >= 4)
        {
            memmove(pAE, "gzip", 4);
            memset(pAE + 4, ' ', len - 4);
        }
    }
    else
    {
        pExtraHeader = m_extraHeader;
        headerLen += 23;
    }
#endif

    if (*(pBegin + --m_iTotalPending - 1) == '\r')
        --m_iTotalPending;
    if (*pForward)
    {
        if ((pBegin + m_iTotalPending) -
            (pForward + pReq->getHeaderLen(HttpHeader::H_X_FORWARDED_FOR)) == 2)
        {
            const char *p = pForward -= 16;
            while (*(p - 1) != '\n')
                --p;
            m_iTotalPending = p - pBegin;
        }
    }

    //reconstruct request line if URL has been rewritten
    if (pReq->getRedirects() > 0)
    {
        const char *pReqLine = pReq->encodeReqLine(newReqLineLen);
        if (newReqLineLen > 0)
        {
            m_iovec.append(pReqLine, newReqLineLen);
            pBegin += pReq->getOrgReqLineLen() - 9;
            m_iTotalPending -= pReq->getOrgReqLineLen() - 9;
        }

    }

    int newHostLen = pReq->getNewHostLen();
    char *pHost = (char *)pReq->getHeader(HttpHeader::H_HOST);
    int hostLen = pReq->getHeaderLen(HttpHeader::H_HOST);
    if (newHostLen > 0)
    {
        if (*pHost)
        {
            m_iovec.append(pBegin, pHost - pBegin);
            m_iovec.append(pReq->getNewHost(), newHostLen);
            m_iovec.append(pHost + hostLen,
                           pBegin + m_iTotalPending - pHost - hostLen);
            m_iTotalPending += (newHostLen - hostLen);
        }
        else
        {
            m_iovec.append(pBegin, m_iTotalPending);
            m_iovec.append("Host: ", 6);
            m_iovec.append(pReq->getNewHost(), newHostLen);
            m_iovec.append("\r\n", 2);
            m_iTotalPending += newHostLen + 8;
        }
    }
    else
        m_iovec.append(pBegin, m_iTotalPending);
    m_iTotalPending += newReqLineLen;
//.........这里部分代码省略.........
开发者ID:52M,项目名称:openlitespeed,代码行数:101,代码来源:proxyconn.cpp


注:本文中的HttpReq::getHeaderLen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。