<commit_before>#include "httprequest.h"
#include "httprequest_p.h"
#include "networkcookiejar.h"

#include <QTimer>
#include <QtDebug>
#include <QtQml>
#include <QNetworkCookie>
#include <QVariant>

QNetworkAccessManager HttpRequest::netwrokAccessManager;

HttpRequest::HttpRequest(QObject *parent) :
    QObject(parent),
    d_ptr(new HttpRequestPrivate(&HttpRequest::netwrokAccessManager, this))
{
    qRegisterMetaType<NetworkStatus>("HttpRequest::NetworkStatus");
    qRegisterMetaType<State>("HttpRequest::State");

    connect(d_ptr, &HttpRequestPrivate::responseTextChanged, this, &HttpRequest::responseTextChanged);
    connect(d_ptr, &HttpRequestPrivate::readyStateChanged, this, &HttpRequest::readyStateChanged);
    connect(d_ptr, &HttpRequestPrivate::statusChanged, this, &HttpRequest::statusChanged);
    connect(d_ptr, &HttpRequestPrivate::statusTextChanged, this, &HttpRequest::statusTextChanged);
    connect(d_ptr, &HttpRequestPrivate::error, this, &HttpRequest::error);
}

HttpRequest::HttpRequest(QNetworkAccessManager *networkManager, QObject *parent):
    QObject(parent),
    d_ptr(new HttpRequestPrivate(networkManager, this))
{
    qRegisterMetaType<NetworkStatus>("HttpRequest::NetworkStatus");
    qRegisterMetaType<State>("HttpRequest::State");

    connect(d_ptr, &HttpRequestPrivate::responseTextChanged, this, &HttpRequest::responseTextChanged);
    connect(d_ptr, &HttpRequestPrivate::readyStateChanged, this, &HttpRequest::readyStateChanged);
    connect(d_ptr, &HttpRequestPrivate::statusChanged, this, &HttpRequest::statusChanged);
    connect(d_ptr, &HttpRequestPrivate::statusTextChanged, this, &HttpRequest::statusTextChanged);
    connect(d_ptr, &HttpRequestPrivate::error, this, &HttpRequest::error);
}

HttpRequest::~HttpRequest()
{
}

void HttpRequest::clear()
{
    d_ptr->clear();
}

void HttpRequest::setTimeout(qint32 time)
{
    if(this->getReadyState() != Loading ) {
        d_ptr->setTimeout(time);
    }
}

int HttpRequest::getTimeout() const
{
    return d_ptr->getTimeout();
}

void HttpRequest::setRequestCookies(const QJsonObject &cookies)
{
    QJsonObject::ConstIterator iter = cookies.begin();
    QJsonObject::ConstIterator end = cookies.end();

    QByteArray cookiesString = "";

    while(iter != end) {
        QByteArray cookieName = iter.key().toUtf8();
        QByteArray cookieValue = iter.value().toString().toUtf8();
        QByteArray cookieString = cookieName + "=" + cookieValue + "; ";
        cookiesString += cookieString;

        iter++;
    }
    this->setRequestHeader("Cookie", cookiesString);
}

void HttpRequest::setRequestHeader(const QJsonObject &headers)
{
    QJsonObject::ConstIterator iter = headers.begin();
    QJsonObject::ConstIterator end = headers.end();

    while(iter != end) {
        this->setRequestHeader(iter.key().toUtf8(), iter.value().toString().toUtf8());
        iter++;
    }
}

void HttpRequest::setRequestHeader(const QByteArray &headerName, const QByteArray &value)
{
    if(d_ptr->getReadyState() == Loading) {
        return ;
    }

    QNetworkRequest request(d_ptr->getRequest());
    request.setRawHeader(headerName, value);
    d_ptr->setRequest(request);
}

QString HttpRequest::getRequestHeader(const QString &headerName) const
{
    return d_ptr->getRequest().rawHeader(headerName.toUtf8());
}

void HttpRequest::open(const QString &method, const QUrl &url, bool async)
{
    Q_UNUSED(async)

    d_ptr->setMethodName(method);
    QNetworkRequest request(d_ptr->getRequest());
    request.setUrl(url);
    d_ptr->setRequest(request);
    d_ptr->setReadyState(HttpRequest::UnStart);<commit_msg>修复  HttpRequest::open 函数<commit_after>#include "httprequest.h"
#include "httprequest_p.h"
#include "networkcookiejar.h"

#include <QTimer>
#include <QtDebug>
#include <QtQml>
#include <QNetworkCookie>
#include <QVariant>

QNetworkAccessManager HttpRequest::netwrokAccessManager;

HttpRequest::HttpRequest(QObject *parent) :
    QObject(parent),
    d_ptr(new HttpRequestPrivate(&HttpRequest::netwrokAccessManager, this))
{
    qRegisterMetaType<NetworkStatus>("HttpRequest::NetworkStatus");
    qRegisterMetaType<State>("HttpRequest::State");

    connect(d_ptr, &HttpRequestPrivate::responseTextChanged, this, &HttpRequest::responseTextChanged);
    connect(d_ptr, &HttpRequestPrivate::readyStateChanged, this, &HttpRequest::readyStateChanged);
    connect(d_ptr, &HttpRequestPrivate::statusChanged, this, &HttpRequest::statusChanged);
    connect(d_ptr, &HttpRequestPrivate::statusTextChanged, this, &HttpRequest::statusTextChanged);
    connect(d_ptr, &HttpRequestPrivate::error, this, &HttpRequest::error);
}

HttpRequest::HttpRequest(QNetworkAccessManager *networkManager, QObject *parent):
    QObject(parent),
    d_ptr(new HttpRequestPrivate(networkManager, this))
{
    qRegisterMetaType<NetworkStatus>("HttpRequest::NetworkStatus");
    qRegisterMetaType<State>("HttpRequest::State");

    connect(d_ptr, &HttpRequestPrivate::responseTextChanged, this, &HttpRequest::responseTextChanged);
    connect(d_ptr, &HttpRequestPrivate::readyStateChanged, this, &HttpRequest::readyStateChanged);
    connect(d_ptr, &HttpRequestPrivate::statusChanged, this, &HttpRequest::statusChanged);
    connect(d_ptr, &HttpRequestPrivate::statusTextChanged, this, &HttpRequest::statusTextChanged);
    connect(d_ptr, &HttpRequestPrivate::error, this, &HttpRequest::error);
}

HttpRequest::~HttpRequest()
{
}

void HttpRequest::clear()
{
    d_ptr->clear();
}

void HttpRequest::setTimeout(qint32 time)
{
    if(this->getReadyState() != Loading ) {
        d_ptr->setTimeout(time);
    }
}

int HttpRequest::getTimeout() const
{
    return d_ptr->getTimeout();
}

void HttpRequest::setRequestCookies(const QJsonObject &cookies)
{
    QJsonObject::ConstIterator iter = cookies.begin();
    QJsonObject::ConstIterator end = cookies.end();

    QByteArray cookiesString = "";

    while(iter != end) {
        QByteArray cookieName = iter.key().toUtf8();
        QByteArray cookieValue = iter.value().toString().toUtf8();
        QByteArray cookieString = cookieName + "=" + cookieValue + "; ";
        cookiesString += cookieString;

        iter++;
    }
    this->setRequestHeader("Cookie", cookiesString);
}

void HttpRequest::setRequestHeader(const QJsonObject &headers)
{
    QJsonObject::ConstIterator iter = headers.begin();
    QJsonObject::ConstIterator end = headers.end();

    while(iter != end) {
        this->setRequestHeader(iter.key().toUtf8(), iter.value().toString().toUtf8());
        iter++;
    }
}

void HttpRequest::setRequestHeader(const QByteArray &headerName, const QByteArray &value)
{
    if(d_ptr->getReadyState() == Loading) {
        return ;
    }

    QNetworkRequest request(d_ptr->getRequest());
    request.setRawHeader(headerName, value);
    d_ptr->setRequest(request);
}

QString HttpRequest::getRequestHeader(const QString &headerName) const
{
    return d_ptr->getRequest().rawHeader(headerName.toUtf8());
}

void HttpRequest::open(const QString &method, const QUrl &url, bool async)
{
    Q_UNUSED(async)

    d_ptr->setMethodName(method);
    QNetworkRequest request(d_ptr->getRequest());
    request.setUrl(url);
    d_ptr->setRequest(request);
    d_ptr->setReadyState(HttpRequest::UnStart);
    Q_EMIT this->abort();
{'fraction_non_alphanumeric': 0.137546468401487, 'fraction_numerical': 0.0019275781357565745, 'mean_word_length': 5.807872539831303, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5353665', 'n_tokens_mistral': 2200, 'n_tokens_neox': 2195, 'n_words': 349}