Skip to content

Commit 763b699

Browse files
author
pfeatherstone
committed
optimizing for coverage. in any case, i think this is better anyway
1 parent cd69cc4 commit 763b699

File tree

7 files changed

+285
-227
lines changed

7 files changed

+285
-227
lines changed

examples/fuzz/request_parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
77
std::string buf(reinterpret_cast<const char*>(data), size);
88
http::request req{};
99
std::error_code ec{};
10-
http::parser<http::request> parser;
10+
http::parser_request parser;
1111
parser.parse(req, buf, ec);
1212
bool is_keep_alive = req.keep_alive();
1313
bool is_websocket_req = req.is_websocket_req();

examples/fuzz/response_parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
77
std::string buf(reinterpret_cast<const char*>(data), size);
88
http::response resp{};
99
std::error_code ec{};
10-
http::parser<http::response> parser;
10+
http::parser_response parser;
1111
parser.parse(resp, buf, ec);
1212
buf.clear();
1313
ec = {};

examples/fuzz/websocket_parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
88

99
http::request req{};
1010
std::error_code ec{};
11-
http::parser<http::request> parser;
11+
http::parser_request parser;
1212
parser.parse(req, buf, ec);
1313
bool is_websocket_req = req.is_websocket_req();
1414

examples/unit_tests/message.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ TEST_SUITE("[MESSAGE]")
115115

116116
http::request req;
117117
std::error_code ec{};
118-
bool finished = http::parser<http::request>{}.parse(req, bad_req, ec);
118+
bool finished = http::parser_request{}.parse(req, bad_req, ec);
119119
REQUIRE(ec == http::http_read_bad_method);
120120
}
121121

@@ -130,7 +130,7 @@ TEST_SUITE("[MESSAGE]")
130130

131131
http::request req;
132132
std::error_code ec{};
133-
bool finished = http::parser<http::request>{}.parse(req, bad_req, ec);
133+
bool finished = http::parser_request{}.parse(req, bad_req, ec);
134134
REQUIRE(ec == http::http_read_unsupported_http_version);
135135
}
136136

@@ -145,7 +145,7 @@ TEST_SUITE("[MESSAGE]")
145145

146146
http::request req;
147147
std::error_code ec{};
148-
bool finished = http::parser<http::request>{}.parse(req, bad_req, ec);
148+
bool finished = http::parser_request{}.parse(req, bad_req, ec);
149149
REQUIRE(ec == http::http_read_unsupported_http_version);
150150
}
151151

@@ -160,7 +160,7 @@ TEST_SUITE("[MESSAGE]")
160160

161161
http::request req;
162162
std::error_code ec{};
163-
bool finished = http::parser<http::request>{}.parse(req, bad_req, ec);
163+
bool finished = http::parser_request{}.parse(req, bad_req, ec);
164164
REQUIRE(ec == http::http_read_unsupported_http_version);
165165
}
166166

@@ -175,7 +175,7 @@ TEST_SUITE("[MESSAGE]")
175175

176176
http::request req;
177177
std::error_code ec{};
178-
bool finished = http::parser<http::request>{}.parse(req, bad_req, ec);
178+
bool finished = http::parser_request{}.parse(req, bad_req, ec);
179179
REQUIRE(ec == http::http_read_header_kv_delimiter_not_found);
180180
}
181181

@@ -191,7 +191,7 @@ TEST_SUITE("[MESSAGE]")
191191

192192
http::request req;
193193
std::error_code ec{};
194-
bool finished = http::parser<http::request>{}.parse(req, bad_req, ec);
194+
bool finished = http::parser_request{}.parse(req, bad_req, ec);
195195
REQUIRE(ec == http::http_read_header_unsupported_field); // (It should be "Host:" not "Host :")
196196
}
197197

@@ -206,7 +206,7 @@ TEST_SUITE("[MESSAGE]")
206206

207207
http::request req;
208208
std::error_code ec{};
209-
bool finished = http::parser<http::request>{}.parse(req, bad_req, ec);
209+
bool finished = http::parser_request{}.parse(req, bad_req, ec);
210210
REQUIRE(!bool(ec));
211211
REQUIRE(!finished); // Incorrect Content-Length
212212
REQUIRE(bad_req.empty());
@@ -222,7 +222,7 @@ TEST_SUITE("[MESSAGE]")
222222

223223
http::request req;
224224
std::error_code ec{};
225-
bool finished = http::parser<http::request>{}.parse(req, bad_req, ec);
225+
bool finished = http::parser_request{}.parse(req, bad_req, ec);
226226
REQUIRE(!bool(ec));
227227
REQUIRE(!finished); // Waiting for \r\n to test header
228228
}
@@ -239,7 +239,7 @@ TEST_SUITE("[MESSAGE]")
239239

240240
http::request req;
241241
std::error_code ec{};
242-
bool finished = http::parser<http::request>{}.parse(req, bad_req, ec);
242+
bool finished = http::parser_request{}.parse(req, bad_req, ec);
243243
REQUIRE(!bool(ec));
244244
REQUIRE(finished); // Done
245245
REQUIRE(bad_req.empty());
@@ -258,7 +258,7 @@ TEST_SUITE("[MESSAGE]")
258258

259259
http::response reply;
260260
std::error_code ec{};
261-
bool finished = http::parser<http::response>{}.parse(reply, bad_reply, ec);
261+
bool finished = http::parser_response{}.parse(reply, bad_reply, ec);
262262
REQUIRE(ec == http::http_read_unsupported_http_version);
263263
}
264264

@@ -272,7 +272,7 @@ TEST_SUITE("[MESSAGE]")
272272

273273
http::response reply;
274274
std::error_code ec{};
275-
bool finished = http::parser<http::response>{}.parse(reply, bad_reply, ec);
275+
bool finished = http::parser_response{}.parse(reply, bad_reply, ec);
276276
REQUIRE(ec == http::http_read_unsupported_http_version);
277277
}
278278

@@ -286,7 +286,7 @@ TEST_SUITE("[MESSAGE]")
286286

287287
http::response reply;
288288
std::error_code ec{};
289-
bool finished = http::parser<http::response>{}.parse(reply, bad_reply, ec);
289+
bool finished = http::parser_response{}.parse(reply, bad_reply, ec);
290290
REQUIRE(ec == http::http_read_unsupported_http_version);
291291
}
292292

@@ -300,7 +300,7 @@ TEST_SUITE("[MESSAGE]")
300300

301301
http::response reply;
302302
std::error_code ec{};
303-
bool finished = http::parser<http::response>{}.parse(reply, bad_reply, ec);
303+
bool finished = http::parser_response{}.parse(reply, bad_reply, ec);
304304
REQUIRE(ec == http::http_read_bad_status);
305305
}
306306

@@ -314,7 +314,7 @@ TEST_SUITE("[MESSAGE]")
314314

315315
http::response reply;
316316
std::error_code ec{};
317-
bool finished = http::parser<http::response>{}.parse(reply, bad_reply, ec);
317+
bool finished = http::parser_response{}.parse(reply, bad_reply, ec);
318318
REQUIRE(ec == http::http_read_header_kv_delimiter_not_found);
319319
}
320320

@@ -328,7 +328,7 @@ TEST_SUITE("[MESSAGE]")
328328

329329
http::response reply;
330330
std::error_code ec{};
331-
bool finished = http::parser<http::response>{}.parse(reply, bad_reply, ec);
331+
bool finished = http::parser_response{}.parse(reply, bad_reply, ec);
332332
REQUIRE(ec == http::http_read_header_unsupported_field);
333333
}
334334

@@ -342,7 +342,7 @@ TEST_SUITE("[MESSAGE]")
342342

343343
http::response reply;
344344
std::error_code ec{};
345-
bool finished = http::parser<http::response>{}.parse(reply, bad_reply, ec);
345+
bool finished = http::parser_response{}.parse(reply, bad_reply, ec);
346346
REQUIRE(ec == http::http_read_header_unsupported_field);
347347
}
348348

@@ -356,7 +356,7 @@ TEST_SUITE("[MESSAGE]")
356356

357357
http::response reply;
358358
std::error_code ec{};
359-
bool finished = http::parser<http::response>{}.parse(reply, bad_reply, ec);
359+
bool finished = http::parser_response{}.parse(reply, bad_reply, ec);
360360
REQUIRE(!bool(ec));
361361
REQUIRE(!finished); // Wrong content length. Waiting for rest of payload
362362
REQUIRE(bad_reply.empty());
@@ -372,7 +372,7 @@ TEST_SUITE("[MESSAGE]")
372372

373373
http::response reply;
374374
std::error_code ec{};
375-
bool finished = http::parser<http::response>{}.parse(reply, good_reply, ec);
375+
bool finished = http::parser_response{}.parse(reply, good_reply, ec);
376376
REQUIRE(!bool(ec));
377377
REQUIRE(finished); // Good
378378
REQUIRE(good_reply.empty());
@@ -449,14 +449,14 @@ TEST_SUITE("[MESSAGE]")
449449

450450
SUBCASE("parse entire message")
451451
{
452-
const bool finished = http::parser<http::request>{}.parse(req1, buf, ec);
452+
const bool finished = http::parser_request{}.parse(req1, buf, ec);
453453
REQUIRE(!bool(ec));
454454
REQUIRE(finished);
455455
}
456456

457457
SUBCASE("parse block by block")
458458
{
459-
http::parser<http::request> parser;
459+
http::parser_request parser;
460460

461461
size_t blocksize{};
462462

@@ -522,14 +522,14 @@ TEST_SUITE("[MESSAGE]")
522522

523523
SUBCASE("parse entire message")
524524
{
525-
const bool finished = http::parser<http::response>{}.parse(resp1, buf, ec);
525+
const bool finished = http::parser_response{}.parse(resp1, buf, ec);
526526
REQUIRE(!bool(ec));
527527
REQUIRE(finished);
528528
}
529529

530530
SUBCASE("parse block by block")
531531
{
532-
http::parser<http::response> parser;
532+
http::parser_response parser;
533533

534534
size_t blocksize{};
535535

0 commit comments

Comments
 (0)