@@ -845,6 +845,9 @@ static void test_http_server(void) {
845
845
ASSERT (fetch (& mgr , buf , url , "GET /a.txt HTTP/1.0\n\n" ) == 200 );
846
846
ASSERT (cmpbody (buf , "hello\n" ) == 0 );
847
847
848
+ // Invalid header: failure
849
+ ASSERT (fetch (& mgr , buf , url , "GET /a.txt HTTP/1.0\nA B\n\n" ) == 0 );
850
+
848
851
ASSERT (fetch (& mgr , buf , url , "GET /%%61.txt HTTP/1.0\n\n" ) == 200 );
849
852
ASSERT (cmpbody (buf , "hello\n" ) == 0 );
850
853
@@ -1351,16 +1354,40 @@ static void test_http_parse(void) {
1351
1354
}
1352
1355
1353
1356
{
1354
- static const char * s = "get b c\nz : k \nb: t\nvvv\n\n xx" ;
1357
+ const char * s = "get b c\nb: t\nv:vv\n\n xx" ;
1358
+ ASSERT (mg_http_parse (s , strlen (s ), & req ) == (int ) strlen (s ) - 3 );
1359
+ }
1360
+
1361
+ {
1362
+ const char * s = "get b c\nb: t\nv:\n\n xx" ;
1363
+ ASSERT (mg_http_parse (s , strlen (s ), & req ) == (int ) strlen (s ) - 3 );
1364
+ }
1365
+
1366
+ {
1367
+ const char * s = "get b c\nb: t\nv v\n\n xx" ;
1368
+ ASSERT (mg_http_parse (s , strlen (s ), & req ) == -1 );
1369
+ }
1370
+
1371
+ {
1372
+ const char * s = "get b c\nb: t\n : aa\n\n" ;
1373
+ ASSERT (mg_http_parse (s , strlen (s ), & req ) == -1 );
1374
+ }
1375
+
1376
+ {
1377
+ const char * s = "get b c\nz: k \nb: t\nv:k\n\n xx" ;
1355
1378
ASSERT (mg_http_parse (s , strlen (s ), & req ) == (int ) strlen (s ) - 3 );
1356
- ASSERT (req .headers [2 ].name .len == 0 );
1379
+ ASSERT (req .headers [3 ].name .len == 0 );
1380
+ ASSERT (mg_vcmp (& req .headers [0 ].name , "z" ) == 0 );
1357
1381
ASSERT (mg_vcmp (& req .headers [0 ].value , "k" ) == 0 );
1382
+ ASSERT (mg_vcmp (& req .headers [1 ].name , "b" ) == 0 );
1358
1383
ASSERT (mg_vcmp (& req .headers [1 ].value , "t" ) == 0 );
1384
+ ASSERT (mg_vcmp (& req .headers [2 ].name , "v" ) == 0 );
1385
+ ASSERT (mg_vcmp (& req .headers [2 ].value , "k" ) == 0 );
1359
1386
ASSERT (req .body .len == 0 );
1360
1387
}
1361
1388
1362
1389
{
1363
- const char * s = "a b c\r\nContent-Length: 21 \r\nb: t\r\nvvv \r\n\r\nabc" ;
1390
+ const char * s = "a b c\r\nContent-Length: 21 \r\nb: t\r\nv:v \r\n\r\nabc" ;
1364
1391
ASSERT (mg_http_parse (s , strlen (s ), & req ) == (int ) strlen (s ) - 3 );
1365
1392
ASSERT (req .body .len == 21 );
1366
1393
ASSERT (req .message .len == 21 - 3 + strlen (s ));
@@ -1452,9 +1479,9 @@ static void test_http_parse(void) {
1452
1479
struct mg_http_message hm ;
1453
1480
const char * s = "a b c\n\n" ;
1454
1481
ASSERT (mg_http_parse (s , strlen (s ), & hm ) == (int ) strlen (s ));
1455
- s = "a b\nc\n\n" ;
1482
+ s = "a b\nc:d \n\n" ;
1456
1483
ASSERT (mg_http_parse (s , strlen (s ), & hm ) == (int ) strlen (s ));
1457
- s = "a\nb\nc\n\n" ;
1484
+ s = "a\nb:b \nc:c \n\n" ;
1458
1485
ASSERT (mg_http_parse (s , strlen (s ), & hm ) < 0 );
1459
1486
}
1460
1487
}
@@ -1922,7 +1949,7 @@ static void test_str(void) {
1922
1949
1923
1950
static void fn1 (struct mg_connection * c , int ev , void * ev_data , void * fn_data ) {
1924
1951
if (ev == MG_EV_ERROR ) {
1925
- ASSERT (* (void * * ) fn_data == NULL );
1952
+ ASSERT (* (void * * ) fn_data == NULL );
1926
1953
* (char * * ) fn_data = mg_mprintf ("%s" , (char * ) ev_data );
1927
1954
}
1928
1955
(void ) c ;
0 commit comments