Skip to content

Commit 0e01591

Browse files
authored
httprequest: use cow types in api (#48413)
1 parent 19a7c6a commit 0e01591

13 files changed

Lines changed: 77 additions & 69 deletions

src/core/httprequest.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#ifndef HTTPREQUEST_H
2525
#define HTTPREQUEST_H
2626

27+
#include "cowbytearray.h"
28+
#include "cowstring.h"
2729
#include "cowurl.h"
2830
#include "httpheaders.h"
2931
#include <QHostAddress>
@@ -51,19 +53,20 @@ class HttpRequest {
5153

5254
virtual QHostAddress peerAddress() const = 0;
5355

54-
virtual void setConnectHost(const QString &host) = 0;
56+
virtual void setConnectHost(const CowString &host) = 0;
5557
virtual void setConnectPort(int port) = 0;
5658
virtual void setIgnorePolicies(bool on) = 0;
5759
virtual void setTrustConnectHost(bool on) = 0;
5860
virtual void setIgnoreTlsErrors(bool on) = 0;
5961
virtual void setTimeout(int msecs) = 0;
60-
virtual void setClientCert(const QString &cert, const QString &key) = 0;
62+
virtual void setClientCert(const CowString &cert, const CowString &key) = 0;
6163

62-
virtual void start(const QString &method, const CowUrl &uri, const HttpHeaders &headers) = 0;
63-
virtual void beginResponse(int code, const QByteArray &reason, const HttpHeaders &headers) = 0;
64+
virtual void start(const CowString &method, const CowUrl &uri, const HttpHeaders &headers) = 0;
65+
virtual void beginResponse(int code, const CowByteArray &reason,
66+
const HttpHeaders &headers) = 0;
6467

6568
// May call this multiple times
66-
virtual void writeBody(const QByteArray &body) = 0;
69+
virtual void writeBody(const CowByteArray &body) = 0;
6770

6871
virtual void endBody() = 0;
6972

@@ -75,15 +78,15 @@ class HttpRequest {
7578
virtual bool isErrored() const = 0;
7679
virtual ErrorCondition errorCondition() const = 0;
7780

78-
virtual QString requestMethod() const = 0;
81+
virtual CowString requestMethod() const = 0;
7982
virtual CowUrl requestUri() const = 0;
8083
virtual HttpHeaders requestHeaders() const = 0;
8184

8285
virtual int responseCode() const = 0;
83-
virtual QByteArray responseReason() const = 0;
86+
virtual CowByteArray responseReason() const = 0;
8487
virtual HttpHeaders responseHeaders() const = 0;
8588

86-
virtual QByteArray readBody(int size = -1) = 0; // Takes from the buffer
89+
virtual CowByteArray readBody(int size = -1) = 0; // Takes from the buffer
8790

8891
// Indicates input data and/or input finished
8992
Signal readyRead;

src/core/zhttprequest.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ class ZhttpRequest::Private {
6666
bool doReq;
6767
QByteArray toAddress;
6868
QHostAddress peerAddress;
69-
QString connectHost;
69+
CowString connectHost;
7070
int connectPort;
7171
bool ignorePolicies;
7272
bool trustConnectHost;
7373
bool ignoreTlsErrors;
7474
int timeout;
75-
QString clientCert;
76-
QString clientKey;
75+
CowString clientCert;
76+
CowString clientKey;
7777
bool sendBodyAfterAck;
7878
Variant passthrough;
79-
QString requestMethod;
79+
CowString requestMethod;
8080
CowUrl requestUri;
8181
HttpHeaders requestHeaders;
8282
BufferList requestBodyBuf;
@@ -88,7 +88,7 @@ class ZhttpRequest::Private {
8888
bool haveRequestBody;
8989
bool haveResponseValues;
9090
int responseCode;
91-
QByteArray responseReason;
91+
CowByteArray responseReason;
9292
HttpHeaders responseHeaders;
9393
BufferList responseBodyBuf;
9494
Variant userData;
@@ -202,10 +202,10 @@ class ZhttpRequest::Private {
202202
if (packet.credits != -1)
203203
outCredits = packet.credits;
204204

205-
requestMethod = packet.method.asQString();
205+
requestMethod = packet.method;
206206
requestUri = packet.uri;
207207
requestHeaders = packet.headers;
208-
requestBodyBuf += packet.body.asQByteArray();
208+
requestBodyBuf += packet.body;
209209

210210
passthrough = packet.passthrough;
211211

@@ -342,7 +342,7 @@ class ZhttpRequest::Private {
342342
}
343343
}
344344

345-
QByteArray readBody(int size) {
345+
CowByteArray readBody(int size) {
346346
if (server) {
347347
QByteArray out = requestBodyBuf.take(size).asQByteArray();
348348
if (out.isEmpty())
@@ -526,7 +526,7 @@ class ZhttpRequest::Private {
526526
refreshTimeout();
527527

528528
if (packet.type == ZhttpRequestPacket::Data) {
529-
requestBodyBuf += packet.body.asQByteArray();
529+
requestBodyBuf += packet.body;
530530

531531
bool done = haveRequestBody;
532532

@@ -664,7 +664,7 @@ class ZhttpRequest::Private {
664664
haveResponseValues = true;
665665

666666
responseCode = packet.code;
667-
responseReason = packet.reason.asQByteArray();
667+
responseReason = packet.reason;
668668
responseHeaders = packet.headers;
669669

670670
needToSendHeaders = true;
@@ -678,7 +678,7 @@ class ZhttpRequest::Private {
678678
log_warning("zhttp client: id=%s server is sending too fast", id.data());
679679
}
680680

681-
responseBodyBuf += packet.body.asQByteArray();
681+
responseBodyBuf += packet.body;
682682

683683
if (packet.more) {
684684
if (!doReq && packet.credits > 0) {
@@ -711,7 +711,7 @@ class ZhttpRequest::Private {
711711
}
712712
}
713713

714-
void writeBody(const QByteArray &body) {
714+
void writeBody(const CowByteArray &body) {
715715
assert(!bodyFinished);
716716
assert(!pausing && !paused);
717717

@@ -1051,7 +1051,7 @@ Variant ZhttpRequest::passthroughData() const { return d->passthrough; }
10511051

10521052
QHostAddress ZhttpRequest::peerAddress() const { return d->peerAddress; }
10531053

1054-
void ZhttpRequest::setConnectHost(const QString &host) { d->connectHost = host; }
1054+
void ZhttpRequest::setConnectHost(const CowString &host) { d->connectHost = host; }
10551055

10561056
void ZhttpRequest::setConnectPort(int port) { d->connectPort = port; }
10571057

@@ -1063,7 +1063,7 @@ void ZhttpRequest::setIgnoreTlsErrors(bool on) { d->ignoreTlsErrors = on; }
10631063

10641064
void ZhttpRequest::setTimeout(int msecs) { d->timeout = msecs; }
10651065

1066-
void ZhttpRequest::setClientCert(const QString &cert, const QString &key) {
1066+
void ZhttpRequest::setClientCert(const CowString &cert, const CowString &key) {
10671067
d->clientCert = cert;
10681068
d->clientKey = key;
10691069
}
@@ -1076,7 +1076,7 @@ void ZhttpRequest::setPassthroughData(const Variant &data) { d->passthrough = da
10761076

10771077
void ZhttpRequest::setQuiet(bool on) { d->quiet = on; }
10781078

1079-
void ZhttpRequest::start(const QString &method, const CowUrl &uri, const HttpHeaders &headers) {
1079+
void ZhttpRequest::start(const CowString &method, const CowUrl &uri, const HttpHeaders &headers) {
10801080
assert(!d->server);
10811081

10821082
d->requestMethod = method;
@@ -1085,7 +1085,7 @@ void ZhttpRequest::start(const QString &method, const CowUrl &uri, const HttpHea
10851085
d->startClient();
10861086
}
10871087

1088-
void ZhttpRequest::beginResponse(int code, const QByteArray &reason, const HttpHeaders &headers) {
1088+
void ZhttpRequest::beginResponse(int code, const CowByteArray &reason, const HttpHeaders &headers) {
10891089
assert(d->server);
10901090
assert(d->state == Private::ServerReceiving || d->state == Private::ServerResponseWait);
10911091

@@ -1095,7 +1095,7 @@ void ZhttpRequest::beginResponse(int code, const QByteArray &reason, const HttpH
10951095
d->beginResponse();
10961096
}
10971097

1098-
void ZhttpRequest::writeBody(const QByteArray &body) { d->writeBody(body); }
1098+
void ZhttpRequest::writeBody(const CowByteArray &body) { d->writeBody(body); }
10991099

11001100
void ZhttpRequest::endBody() { d->endBody(); }
11011101

@@ -1164,19 +1164,19 @@ bool ZhttpRequest::isErrored() const { return d->errored; }
11641164

11651165
HttpRequest::ErrorCondition ZhttpRequest::errorCondition() const { return d->errorCondition; }
11661166

1167-
QString ZhttpRequest::requestMethod() const { return d->requestMethod; }
1167+
CowString ZhttpRequest::requestMethod() const { return d->requestMethod; }
11681168

11691169
CowUrl ZhttpRequest::requestUri() const { return d->requestUri; }
11701170

11711171
HttpHeaders ZhttpRequest::requestHeaders() const { return d->requestHeaders; }
11721172

11731173
int ZhttpRequest::responseCode() const { return d->responseCode; }
11741174

1175-
QByteArray ZhttpRequest::responseReason() const { return d->responseReason; }
1175+
CowByteArray ZhttpRequest::responseReason() const { return d->responseReason; }
11761176

11771177
HttpHeaders ZhttpRequest::responseHeaders() const { return d->responseHeaders; }
11781178

1179-
QByteArray ZhttpRequest::readBody(int size) { return d->readBody(size); }
1179+
CowByteArray ZhttpRequest::readBody(int size) { return d->readBody(size); }
11801180

11811181
void ZhttpRequest::setupClient(ZhttpManager *manager, bool req) {
11821182
d->manager = manager;

src/core/zhttprequest.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#ifndef ZHTTPREQUEST_H
2525
#define ZHTTPREQUEST_H
2626

27+
#include "cowbytearray.h"
28+
#include "cowstring.h"
2729
#include "cowurl.h"
2830
#include "httprequest.h"
2931
#include "variant.h"
@@ -46,10 +48,10 @@ class ZhttpRequest : public HttpRequest {
4648
public:
4749
Rid rid;
4850
QHostAddress peerAddress;
49-
QString requestMethod;
51+
CowString requestMethod;
5052
CowUrl requestUri;
5153
HttpHeaders requestHeaders;
52-
QByteArray requestBody;
54+
CowByteArray requestBody;
5355
int responseCode;
5456
int inSeq;
5557
int outSeq;
@@ -79,18 +81,18 @@ class ZhttpRequest : public HttpRequest {
7981

8082
virtual QHostAddress peerAddress() const;
8183

82-
virtual void setConnectHost(const QString &host);
84+
virtual void setConnectHost(const CowString &host);
8385
virtual void setConnectPort(int port);
8486
virtual void setIgnorePolicies(bool on);
8587
virtual void setTrustConnectHost(bool on);
8688
virtual void setIgnoreTlsErrors(bool on);
8789
virtual void setTimeout(int msecs);
88-
virtual void setClientCert(const QString &cert, const QString &key);
90+
virtual void setClientCert(const CowString &cert, const CowString &key);
8991

90-
virtual void start(const QString &method, const CowUrl &uri, const HttpHeaders &headers);
91-
virtual void beginResponse(int code, const QByteArray &reason, const HttpHeaders &headers);
92+
virtual void start(const CowString &method, const CowUrl &uri, const HttpHeaders &headers);
93+
virtual void beginResponse(int code, const CowByteArray &reason, const HttpHeaders &headers);
9294

93-
virtual void writeBody(const QByteArray &body);
95+
virtual void writeBody(const CowByteArray &body);
9496

9597
virtual void endBody();
9698

@@ -102,15 +104,15 @@ class ZhttpRequest : public HttpRequest {
102104
virtual bool isErrored() const;
103105
virtual ErrorCondition errorCondition() const;
104106

105-
virtual QString requestMethod() const;
107+
virtual CowString requestMethod() const;
106108
virtual CowUrl requestUri() const;
107109
virtual HttpHeaders requestHeaders() const;
108110

109111
virtual int responseCode() const;
110-
virtual QByteArray responseReason() const;
112+
virtual CowByteArray responseReason() const;
111113
virtual HttpHeaders responseHeaders() const;
112114

113-
virtual QByteArray readBody(int size = -1);
115+
virtual CowByteArray readBody(int size = -1);
114116

115117
private:
116118
class Private;

src/handler/filter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ class HttpFilterInner {
341341
}
342342
}
343343

344-
QByteArray body = req->readBody();
344+
QByteArray body = req->readBody().asQByteArray();
345345

346346
if (mode == HttpFilter::Modify) {
347347
if (responseSizeMax >= 0 && responseBody.size() + body.size() > responseSizeMax) {

src/handler/filtertest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class HttpFilterServer {
105105
}
106106

107107
CowUrl uri = req->requestUri();
108-
QByteArray body = req->readBody();
108+
QByteArray body = req->readBody().asQByteArray();
109109
bool preferInternal = req->passthroughData().toMap().value("prefer-internal").toBool();
110110

111111
if (uri.path() == "/filter/accept") {

src/handler/httpsession.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ class HttpSession::Private {
10861086
if (avail <= 0)
10871087
return;
10881088

1089-
QByteArray buf = outReq->readBody(avail);
1089+
QByteArray buf = outReq->readBody(avail).asQByteArray();
10901090

10911091
if (responseFilters) {
10921092
buf = responseFilters->update(buf);
@@ -1197,8 +1197,8 @@ class HttpSession::Private {
11971197
}
11981198
}
11991199

1200-
void logRequest(const QString &method, const CowUrl &uri, const HttpHeaders &headers, int code,
1201-
int bodySize) {
1200+
void logRequest(const CowString &method, const CowUrl &uri, const HttpHeaders &headers,
1201+
int code, int bodySize) {
12021202
LogUtil::RequestData rd;
12031203

12041204
// Only log route id if explicitly set
@@ -1218,7 +1218,7 @@ class HttpSession::Private {
12181218
LogUtil::logRequest(LOG_LEVEL_INFO, rd, logConfig);
12191219
}
12201220

1221-
void logRequestError(const QString &method, const CowUrl &uri, const HttpHeaders &headers) {
1221+
void logRequestError(const CowString &method, const CowUrl &uri, const HttpHeaders &headers) {
12221222
LogUtil::RequestData rd;
12231223

12241224
// Only log route id if explicitly set

src/proxy/proxysession.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ class ProxySession::Private {
485485
if (maxBytes == 0)
486486
return;
487487

488-
QByteArray buf = inRequest->request()->readBody(maxBytes);
488+
QByteArray buf = inRequest->request()->readBody(maxBytes).asQByteArray();
489489
if (!buf.isEmpty()) {
490490
log_debug("proxysession: %p input chunk: %d", q, buf.size());
491491

@@ -792,7 +792,7 @@ class ProxySession::Private {
792792
QByteArray buf;
793793
int maxBytes = (buffering ? MAX_INITIAL_BUFFER - responseBody.size() : MAX_STREAM_BUFFER);
794794
if (maxBytes > 0)
795-
buf = zhttpRequest->readBody(maxBytes);
795+
buf = zhttpRequest->readBody(maxBytes).asQByteArray();
796796

797797
if (!buf.isEmpty()) {
798798
incCounter(Stats::ServerContentBytesReceived, buf.size());
@@ -960,7 +960,7 @@ class ProxySession::Private {
960960
responseData.reason = zhttpRequest->responseReason();
961961
responseData.headers = zhttpRequest->responseHeaders();
962962

963-
QByteArray buf = zhttpRequest->readBody(MAX_INITIAL_BUFFER);
963+
QByteArray buf = zhttpRequest->readBody(MAX_INITIAL_BUFFER).asQByteArray();
964964

965965
incCounter(Stats::ServerHeaderBytesReceived,
966966
ZhttpManager::estimateResponseHeaderBytes(responseData.code,

src/proxy/requestsession.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ class RequestSession::Private {
457457
q->inspected(idata);
458458
}
459459
} else if (state == ReceivingForAccept) {
460-
QByteArray buf = zhttpRequest->readBody();
460+
QByteArray buf = zhttpRequest->readBody().asQByteArray();
461461
if (in.size() + buf.size() > MAX_ACCEPT_REQUEST_BODY) {
462462
respondError(413, "Request Entity Too Large",
463463
QString("Body must not exceed %1 bytes").arg(MAX_ACCEPT_REQUEST_BODY));

src/proxy/sockjsmanager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ class SockJsManager::Private {
371371
}
372372

373373
void handleRequest(Session *s) {
374-
QString method = s->req->requestMethod();
374+
CowString method = s->req->requestMethod();
375375
log_debug("sockjs request: path=[%s], asUri=[%s]", s->path.data(),
376376
s->asUri.toEncoded().data());
377377

0 commit comments

Comments
 (0)