11/*
22 * Copyright (C) 2012-2017 Fanout, Inc.
3+ * Copyright (C) 2025 Fastly, Inc.
34 *
45 * $FANOUT_BEGIN_LICENSE:APACHE2$
56 *
2122#include " httpheaders.h"
2223
2324// return position, end of string if not found, -1 on error
24- static int findNonQuoted (const QByteArray &in, char c, int offset = 0 )
25+ static int findNonQuoted (const CowByteArray &in, char c, int offset = 0 )
2526{
2627 bool inQuote = false ;
2728
@@ -67,7 +68,7 @@ static int findNonQuoted(const QByteArray &in, char c, int offset = 0)
6768}
6869
6970// search for one of many chars
70- static int findNext (const QByteArray &in, const char *charList, int offset = 0 )
71+ static int findNext (const CowByteArray &in, const char *charList, int offset = 0 )
7172{
7273 int len = qstrlen (charList);
7374 for (int n = offset; n < in.size (); ++n)
@@ -83,9 +84,9 @@ static int findNext(const QByteArray &in, const char *charList, int offset = 0)
8384 return -1 ;
8485}
8586
86- static QList<QByteArray> headerSplit (const QByteArray &in)
87+ static CowByteArrayList headerSplit (const CowByteArray &in)
8788{
88- QList<QByteArray> parts;
89+ CowByteArrayList parts;
8990 int pos = 0 ;
9091 while (pos < in.size ())
9192 {
@@ -109,7 +110,7 @@ static QList<QByteArray> headerSplit(const QByteArray &in)
109110 return parts;
110111}
111112
112- bool HttpHeaderParameters::contains (const QByteArray &key) const
113+ bool HttpHeaderParameters::contains (const CowByteArray &key) const
113114{
114115 for (int n = 0 ; n < count (); ++n)
115116 {
@@ -120,7 +121,7 @@ bool HttpHeaderParameters::contains(const QByteArray &key) const
120121 return false ;
121122}
122123
123- QByteArray HttpHeaderParameters::get (const QByteArray &key) const
124+ CowByteArray HttpHeaderParameters::get (const CowByteArray &key) const
124125{
125126 for (int n = 0 ; n < count (); ++n)
126127 {
@@ -129,10 +130,10 @@ QByteArray HttpHeaderParameters::get(const QByteArray &key) const
129130 return h.second ;
130131 }
131132
132- return QByteArray ();
133+ return CowByteArray ();
133134}
134135
135- bool HttpHeaders::contains (const QByteArray &key) const
136+ bool HttpHeaders::contains (const CowByteArray &key) const
136137{
137138 for (int n = 0 ; n < count (); ++n)
138139 {
@@ -143,7 +144,7 @@ bool HttpHeaders::contains(const QByteArray &key) const
143144 return false ;
144145}
145146
146- QByteArray HttpHeaders::get (const QByteArray &key) const
147+ CowByteArray HttpHeaders::get (const CowByteArray &key) const
147148{
148149 for (int n = 0 ; n < count (); ++n)
149150 {
@@ -152,30 +153,30 @@ QByteArray HttpHeaders::get(const QByteArray &key) const
152153 return h.second ;
153154 }
154155
155- return QByteArray ();
156+ return CowByteArray ();
156157}
157158
158- HttpHeaderParameters HttpHeaders::getAsParameters (const QByteArray &key, ParseMode mode) const
159+ HttpHeaderParameters HttpHeaders::getAsParameters (const CowByteArray &key, ParseMode mode) const
159160{
160- QByteArray h = get (key);
161+ CowByteArray h = get (key);
161162 if (h.isEmpty ())
162163 return HttpHeaderParameters ();
163164
164165 return parseParameters (h, mode);
165166}
166167
167- QByteArray HttpHeaders::getAsFirstParameter (const QByteArray &key) const
168+ CowByteArray HttpHeaders::getAsFirstParameter (const CowByteArray &key) const
168169{
169170 HttpHeaderParameters p = getAsParameters (key);
170171 if (p.isEmpty ())
171- return QByteArray ();
172+ return CowByteArray ();
172173
173174 return p[0 ].first ;
174175}
175176
176- QList<QByteArray> HttpHeaders::getAll (const QByteArray &key, bool split) const
177+ CowByteArrayList HttpHeaders::getAll (const CowByteArray &key, bool split) const
177178{
178- QList<QByteArray> out;
179+ CowByteArrayList out;
179180
180181 for (int n = 0 ; n < count (); ++n)
181182 {
@@ -192,11 +193,12 @@ QList<QByteArray> HttpHeaders::getAll(const QByteArray &key, bool split) const
192193 return out;
193194}
194195
195- QList<HttpHeaderParameters> HttpHeaders::getAllAsParameters (const QByteArray &key, ParseMode mode, bool split) const
196+ QList<HttpHeaderParameters> HttpHeaders::getAllAsParameters (const CowByteArray &key, ParseMode mode, bool split) const
196197{
197198 QList<HttpHeaderParameters> out;
198199
199- foreach (const QByteArray &h, getAll (key, split))
200+ CowByteArrayList l = getAll (key, split);
201+ for (CowByteArrayConstRef h : std::as_const (l))
200202 {
201203 bool ok;
202204 HttpHeaderParameters params = parseParameters (h, mode, &ok);
@@ -207,9 +209,9 @@ QList<HttpHeaderParameters> HttpHeaders::getAllAsParameters(const QByteArray &ke
207209 return out;
208210}
209211
210- QList<QByteArray> HttpHeaders::takeAll (const QByteArray &key, bool split)
212+ CowByteArrayList HttpHeaders::takeAll (const CowByteArray &key, bool split)
211213{
212- QList<QByteArray> out;
214+ CowByteArrayList out;
213215
214216 for (int n = 0 ; n < count (); ++n)
215217 {
@@ -229,7 +231,7 @@ QList<QByteArray> HttpHeaders::takeAll(const QByteArray &key, bool split)
229231 return out;
230232}
231233
232- void HttpHeaders::removeAll (const QByteArray &key)
234+ void HttpHeaders::removeAll (const CowByteArray &key)
233235{
234236 for (int n = 0 ; n < count (); ++n)
235237 {
@@ -241,12 +243,12 @@ void HttpHeaders::removeAll(const QByteArray &key)
241243 }
242244}
243245
244- QByteArray HttpHeaders::join (const QList<QByteArray> &values)
246+ CowByteArray HttpHeaders::join (const CowByteArrayList &values)
245247{
246- QByteArray out;
248+ CowByteArray out;
247249
248250 bool first = true ;
249- foreach ( const QByteArray & val, values)
251+ for (CowByteArrayConstRef val : std::as_const ( values) )
250252 {
251253 if (!first)
252254 out += " , " ;
@@ -258,7 +260,7 @@ QByteArray HttpHeaders::join(const QList<QByteArray> &values)
258260 return out;
259261}
260262
261- HttpHeaderParameters HttpHeaders::parseParameters (const QByteArray &in, ParseMode mode, bool *ok)
263+ HttpHeaderParameters HttpHeaders::parseParameters (const CowByteArray &in, ParseMode mode, bool *ok)
262264{
263265 HttpHeaderParameters out;
264266
@@ -268,20 +270,20 @@ HttpHeaderParameters HttpHeaders::parseParameters(const QByteArray &in, ParseMod
268270 int at = in.indexOf (' ;' );
269271 if (at != -1 )
270272 {
271- out += HttpHeaderParameter (in.mid (0 , at).trimmed (), QByteArray ());
273+ out += HttpHeaderParameter (in.mid (0 , at).trimmed (), CowByteArray ());
272274 start = at + 1 ;
273275 }
274276 else
275277 {
276- out += HttpHeaderParameter (in.trimmed (), QByteArray ());
278+ out += HttpHeaderParameter (in.trimmed (), CowByteArray ());
277279 start = in.size ();
278280 }
279281 }
280282
281283 while (start < in.size ())
282284 {
283- QByteArray var;
284- QByteArray val;
285+ CowByteArray var;
286+ CowByteArray val;
285287
286288 int at = findNext (in, " =;" , start);
287289 if (at != -1 )
0 commit comments