src/transaction.cc
/**
 * @name    addRequestHeader
 * @brief   Adds a request header
 *
 * With this method it is possible to feed ModSecurity with a request header.
 *
 * @note This function expects a NULL terminated string, for both: key and
 *       value.
 *
 * @param key   header name.
 * @param value header value.
 *
 * @returns If the operation was successful or not.
 * @retval true Operation was successful.
 * @retval false Operation failed.
 *
 */
@name    addRequestHeader
@brief   Adds a request header

With this method it is possible to feed ModSecurity with a request header.

@note This function expects a NULL terminated string, for both: key and
value.

@param key   header name.
@param value header value.

@returns If the operation was successful or not.
@retval true Operation was successful.
@retval false Operation failed.
@name addRequestHeader @brief Adds a request header With this method it is possible to feed ModSecurity with a request header . @note This function expects a NULL terminated string for both : key and value . @param key header name . @param value header value . @returns If the operation was successful or not . @retval true Operation was successful . @retval false Operation failed .
int Transaction::addRequestHeader(const std::string& key,
    const std::string& value) {
    m_requestHeadersNames->assign(*m_requestHeadersNames + " " + key);
    this->m_collections.store("REQUEST_HEADERS:" + key, value);
    std::string keyl = utils::string::tolower(key);
    if (keyl == "authorization") {
        std::vector<std::string> type = utils::string::split(value, ' ');
        this->m_collections.store("AUTH_TYPE", type[0]);
    }
    if (keyl == "cookie") {
        std::vector<std::string> cookies = utils::string::split(value, ';');
        while (cookies.empty() == false) {
            std::vector<std::string> s = utils::string::split(cookies.back(),
               '=');
            if (s.size() > 1) {
                if (s[0].at(0) == ' ') {
                    s[0].erase(0, 1);
                }
                this->m_collections.store("REQUEST_COOKIES:"
                    + s[0], s[1]);
                this->m_collections.store("REQUEST_COOKIES_NAMES:"
                    + s[0], s[0]);
            }
            cookies.pop_back();
        }
    }
    if (keyl == "content-type") {
        std::string multipart("multipart/form-data");
        std::string l = utils::string::tolower(value);
        if (l.compare(0, multipart.length(), multipart) == 0) {
            this->m_requestBodyType = MultiPartRequestBody;
            m_collections.store("REQBODY_PROCESSOR", "MULTIPART");
        }
        if (l == "application/x-www-form-urlencoded") {
            this->m_requestBodyType = WWWFormUrlEncoded;
            m_collections.store("REQBODY_PROCESSOR", "URLENCODED");
        }
    }
    if (keyl == "host") {
        std::vector<std::string> host = utils::string::split(value, ':');
        m_collections.store("SERVER_NAME", host[0]);
    }
    return 1;
}
int Transaction :: addRequestHeader ( const std :: string & key , const std :: string & value ) { m_requestHeadersNames -> assign ( * m_requestHeadersNames + " " + key ) ; this -> m_collections . store ( " " + key , value ) ; std :: string keyl = utils :: string :: tolower ( key ) ; if ( keyl == " " ) { std :: vector < std :: string > type = utils :: string :: split ( value , ' ' ) ; this -> m_collections . store ( " " , type [ 0 ] ) ; } if ( keyl == " " ) { std :: vector < std :: string > cookies = utils :: string :: split ( value , ' ' ) ; while ( cookies . empty ( ) == false ) { std :: vector < std :: string > s = utils :: string :: split ( cookies . back ( ) , ' ' ) ; if ( s . size ( ) > 1 ) { if ( s [ 0 ] . at ( 0 ) == ' ' ) { s [ 0 ] . erase ( 0 , 1 ) ; } this -> m_collections . store ( " " + s [ 0 ] , s [ 1 ] ) ; this -> m_collections . store ( " " + s [ 0 ] , s [ 0 ] ) ; } cookies . pop_back ( ) ; } } if ( keyl == " " ) { std :: string multipart ( " " ) ; std :: string l = utils :: string :: tolower ( value ) ; if ( l . compare ( 0 , multipart . length ( ) , multipart ) == 0 ) { this -> m_requestBodyType = MultiPartRequestBody ; m_collections . store ( " " , " " ) ; } if ( l == " " ) { this -> m_requestBodyType = WWWFormUrlEncoded ; m_collections . store ( " " , " " ) ; } } if ( keyl == " " ) { std :: vector < std :: string > host = utils :: string :: split ( value , ' ' ) ; m_collections . store ( " " , host [ 0 ] ) ; } return 1 ; }
@name    addRequestHeader
 @brief   Adds a request header
@name addRequestHeader @brief Adds a request header
/**
     * Simple check to decide the request body content. This is not the right
     * place, the "body processor" should be able to tell what he is capable
     * to deal with.
     *
     */