forked from azadkuh/qhttp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqhttpclientrequest.cpp
More file actions
98 lines (78 loc) · 2.36 KB
/
Copy pathqhttpclientrequest.cpp
File metadata and controls
98 lines (78 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "private/qhttpclientrequest_private.hpp"
#include "qhttpclient.hpp"
///////////////////////////////////////////////////////////////////////////////
namespace qhttp {
namespace client {
///////////////////////////////////////////////////////////////////////////////
QHttpRequest::QHttpRequest(QHttpClient* cli)
: QHttpAbstractOutput(cli) , d_ptr(new QHttpRequestPrivate(cli, this)) {
d_ptr->initialize();
QHTTP_LINE_LOG
}
QHttpRequest::QHttpRequest(QHttpRequestPrivate& dd, QHttpClient* cli)
: QHttpAbstractOutput(cli) , d_ptr(&dd) {
d_ptr->initialize();
QHTTP_LINE_LOG
}
QHttpRequest::~QHttpRequest() {
QHTTP_LINE_LOG
}
void
QHttpRequest::setVersion(const QString &versionString) {
d_func()->iversion = versionString;
}
void
QHttpRequest::addHeader(const QByteArray &field, const QByteArray &value) {
d_func()->addHeader(field, value);
}
THeaderHash&
QHttpRequest::headers() {
return d_func()->iheaders;
}
void
QHttpRequest::write(const QByteArray &data) {
d_func()->writeData(data);
}
void
QHttpRequest::end(const QByteArray &data) {
Q_D(QHttpRequest);
if ( d->endPacket(data) )
emit done(!d->ikeepAlive);
}
QHttpClient*
QHttpRequest::connection() const {
return d_func()->iclient;
}
///////////////////////////////////////////////////////////////////////////////
QByteArray
QHttpRequestPrivate::makeTitle() {
QByteArray title;
title.reserve(512);
title.append(qhttp::Stringify::toString(imethod))
.append(" ");
QByteArray path = iurl.path(QUrl::FullyEncoded).toLatin1();
if ( path.size() == 0 )
path = "/";
title.append(path);
if ( iurl.hasQuery() )
title.append("?").append(iurl.query(QUrl::FullyEncoded).toLatin1());
title.append(" HTTP/")
.append(iversion.toLatin1())
.append("\r\n");
return title;
}
void
QHttpRequestPrivate::prepareHeadersToWrite() {
if ( !iheaders.contains("host") ) {
quint16 port = iurl.port();
if ( port == 0 )
port = 80;
iheaders.insert("host",
QString("%1:%2").arg(iurl.host()).arg(port).toLatin1()
);
}
}
///////////////////////////////////////////////////////////////////////////////
} // namespace client
} // namespace qhttp
///////////////////////////////////////////////////////////////////////////////