/*!
  Sets the raw header \a key to be of value \a value.
  If \a key was previously set, it is added multiply.
*/
void TInternetMessageHeader::addRawHeader(const QByteArray &key, const QByteArray &value)
{
    if (key.isEmpty() || value.isNull())
        return;

    headerPairList << RawHeaderPair(key, value);
}
/*!
  Sets the raw header \a key to be of value \a value.
  If \a key was previously set, it is overridden.
*/
void TInternetMessageHeader::setRawHeader(const QByteArray &key, const QByteArray &value)
{
    if (!hasRawHeader(key)) {
        headerPairList << RawHeaderPair(key, value);
        return;
    }
    
    QByteArray val = value;
    for (QMutableListIterator<RawHeaderPair> i(headerPairList); i.hasNext(); ) {
        RawHeaderPair &p = i.next();
        if (qstricmp(p.first.constData(), key.constData()) == 0) {
            if (val.isNull()) {
                i.remove();
            } else {
                p.second = val;
                val.clear();
            }
        }
    }
}
void QtNetworkReplyThreadSafeProxy::localMirrorMembers()
{
    ASSERT(m_reply);
    QMutexLocker lock(&m_mirroredMembersMutex);

    m_contentDispositionHeader = m_reply->rawHeader("Content-Disposition");
    m_contentLengthHeader = m_reply->header(QNetworkRequest::ContentLengthHeader).toLongLong();
    m_contentTypeHeader = m_reply->header(QNetworkRequest::ContentTypeHeader).toString();
    m_error = m_reply->error();
    m_errorString = m_reply->errorString();
    m_httpReasonPhrase = m_reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toByteArray();
    m_httpStatusCode = m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
    m_url = m_reply->url();
    m_redirectionTarget = m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
    m_rawHeaderPairs = m_reply->rawHeaderPairs();
#else
    m_rawHeaderPairs.clear();
    foreach (const QByteArray& headerName, m_reply->rawHeaderList())
        m_rawHeaderPairs.append(RawHeaderPair(headerName, m_reply->rawHeader(headerName)));
#endif
}