Exemple #1
0
    void Message::setHeader(const MessageHeader& header)
    {
        MessageHeaderSeq::iterator it(_headers.begin());
        while(it != _headers.end())
        {
            MessageHeader* pHeader = *it;
            if(header.key() == pHeader->key())
            {
                pHeader->setValue(header.value());
                return;
            }
            ++it;
        }

        _headers.push_back(new MessageHeader(header));
    }
Exemple #2
0
    size_t Message::headerLen() const
    {
        size_t nLen = 0;
        MessageHeaderSeq::const_iterator it(_headers.begin());
        while(it != _headers.end())
        {
            MessageHeader* pHeader = *it;
            if(pHeader != NULL)
            {
                nLen += (pHeader->key().size() + 2 + pHeader->value().size() + 2);
            }
            ++it;
        }

        return nLen;
    }
Exemple #3
0
 void Message::removeHeader(const std::string&key) 
 {
     MessageHeaderSeq::iterator it(_headers.begin());
     while(it != _headers.end())
     {
         MessageHeader* pHeader = *it;
         if(key == pHeader->key())
         {
             it = _headers.erase(it);
         }
         else
         {
             ++it;
         }
     }
 }
Exemple #4
0
    void Message::setHeader(const std::string& key, const std::string& value)
    {
        MessageHeaderSeq::iterator it(_headers.begin());
        while(it != _headers.end())
        {
            MessageHeader* pHeader = *it;
            if(key == pHeader->key())
            {
                pHeader->setValue(value);
                return;
            }
            ++it;
        }

        _headers.push_back(new MessageHeader(key, value));
    }
Exemple #5
0
    std::string Message::header(const std::string& key) const
    {
        std::string value;
        MessageHeaderSeq::const_iterator it(_headers.begin());
        while(it != _headers.end())
        {
            MessageHeader* pHeader = *it;
            if(key == pHeader->key())
            {
                value = pHeader->value();
                break;
            }
            ++it;
        }

        return value;
    }
Exemple #6
0
    std::string ResponseMessage::dump() const
    {
        // <protocol>/<version> code message CRLF
        // <headers> CRLF 
        // <buf>
        std::ostringstream oss;

        oss << _protocol << "/" << _version << " " << _code << " " << _reason << "\r\n";

        for(size_t i = 0; i < headerCount(); i++)
        {
            MessageHeader* pHeader = header(i);
            oss << pHeader->key() << ":" << pHeader->value() << "\r\n";
        }

        oss << "\r\n";

        oss << "Body (" << _bodyLen << "bytes)" << "\r\n";

        return oss.str();
    }
Exemple #7
0
    std::string RequestMessage::dump() const
    {
        // <verb> SP <url> SP <protocol/version> CRLF
        // <headers> CRLF 
        // <buf>
        std::ostringstream oss;

        oss << _method << " " << _url << " " << _protocol << "/" << _version << "\r\n";

        for(size_t i = 0; i < headerCount(); i++)
        {
            MessageHeader* pHeader = header(i);
            oss << pHeader->key() << ":" << pHeader->value() << "\r\n";
        }

        oss << "\r\n";

        oss << "Body (" << _bodyLen << "bytes)\r\n";

        return oss.str();
    }