4 #include <QHostAddress>
21 void write(
const QByteArray &data);
25 static int Url(
http_parser *parser,
const char *at,
size_t length);
55 m_parserSettings(nullptr),
117 QByteArray arr =
m_socket->readAll();
135 d->m_socket = socket;
138 connect(socket, SIGNAL(readyRead()),
this, SLOT(
parseRequest()));
140 connect(socket, SIGNAL(bytesWritten(qint64)),
this, SLOT(
updateWriteCount(qint64)));
152 d->invalidateRequest();
158 d->writeCount(count);
176 d->m_socket->flush();
182 d->m_socket->waitForBytesWritten();
191 d->m_socket->disconnectFromHost();
196 #define HAS_URL_FIELD(info, field) (info.field_set &(1 << (field)))
198 #define GET_FIELD(data, info, field) \
199 QString::fromLatin1(data + info.field_data[field].off, info.field_data[field].len)
201 #define CHECK_AND_GET_FIELD(data, info, field) \
202 (HAS_URL_FIELD(info, field) ? GET_FIELD(data, info, field) : QString())
210 #if TTK_QT_VERSION_CHECK(5,0,0)
225 url.setPort(urlInfo.
port);
231 #undef CHECK_AND_SET_FIELD
272 parser->
method == HTTP_CONNECT, &urlInfo);
292 QObject::connect(theConnection->
m_parent, SIGNAL(destroyed()), response, SLOT(connectionClosed()));
293 QObject::connect(response, SIGNAL(done()), theConnection->
m_parent, SLOT(responseDone()));
338 QString fieldSuffix = QString::fromLatin1(at, length);
348 QString valueSuffix = QString::fromLatin1(at, length);
358 Q_EMIT theConnection->
m_request->
data(QByteArray(at, length));
static int HeaderField(http_parser *parser, const char *at, size_t length)
HttpMethod
Request method enumeration.
#define TTKStaticCast(x, y)
QHttpConnection * m_parent
The class of the http response.
The class of the http connection.
The class of the http connection private.
void write(const QByteArray &data)
void setUrl(const QUrl &url)
http_data_cb on_header_field
http_cb on_headers_complete
unsigned short http_minor
void writeCount(qint64 count)
QHttpConnection(QTcpSocket *socket, QObject *parent=nullptr)
void setKeepAlive(bool alive)
void newRequest(QHttpRequest *request, QHttpResponse *response)
~QHttpConnectionPrivate()
void setHeaders(const HeaderHash headers)
size_t http_parser_execute(http_parser *parser, const http_parser_settings *settings, const char *data, size_t len)
static int MessageComplete(http_parser *parser)
void setRemotePort(quint16 port)
The class of the http request.
static int HeaderValue(http_parser *parser, const char *at, size_t length)
void data(const QByteArray &data)
Emitted when new body data has been received.
QString m_currentHeaderField
void waitForBytesWritten()
void end()
Emitted when the request has been fully received.
HeaderHash m_currentHeaders
void setSuccessful(bool success)
int http_parser_parse_url(const char *buf, size_t buflen, int is_connect, struct http_parser_url *u)
QString m_currentHeaderValue
void setVersion(const QString &version)
bool successful() const
If this request was successfully received.
unsigned short http_major
READ-ONLY.
void setRemoteAddress(const QString &address)
void setMethod(HttpMethod method)
void write(const QByteArray &data)
struct http_parser_url::@3 field_data[UF_MAX]
void http_parser_init(http_parser *parser, enum http_parser_type t)
http_data_cb on_header_value
QHash< QString, QString > HeaderHash
static int HeadersComplete(http_parser *parser)
QUrl createUrl(const char *urlData, const http_parser_url &urlInfo)
void updateWriteCount(qint64)
static int Url(http_parser *parser, const char *at, size_t length)
#define TTK_INIT_PRIVATE(Class)
#define CHECK_AND_GET_FIELD(data, info, field)
#define HAS_URL_FIELD(info, field)
The class of the ttk private base.
static int MessageBegin(http_parser *parser)
void socketDisconnected()
struct http_parser_settings http_parser_settings
static int Body(http_parser *parser, const char *at, size_t length)
http_cb on_message_complete
http_parser_settings * m_parserSettings
#define TTKObjectCast(x, y)