libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

test_response_entries.c (29228B)


      1 /*
      2      This file is part of libmicrohttpd
      3      Copyright (C) 2021 Karlson2k (Evgeny Grin)
      4 
      5      This test_response_entries.c file is in the public domain
      6 */
      7 
      8 /**
      9  * @file test_response_entries.c
     10  * @brief  Test adding and removing response headers
     11  * @author Karlson2k (Evgeny Grin)
     12  */
     13 #include "mhd_options.h"
     14 #include "platform.h"
     15 #include <string.h>
     16 #include <microhttpd.h>
     17 
     18 /* Turn any MHD_PANIC() or failing mhd_assert() reached from this
     19    test into a marked, classifiable test error (TESTING.md, P5). */
     20 #include "mhd_panic_tripwire.h"
     21 
     22 
     23 static int
     24 expect_str (const char *actual, const char *expected)
     25 {
     26   if (expected == actual)
     27     return ! 0;
     28   if (NULL == actual)
     29   {
     30     fprintf (stderr, "FAILED: result: NULL\n" \
     31              "        expected: \"%s\"\n",
     32              expected);
     33     return 0;
     34   }
     35   if (NULL == expected)
     36   {
     37     fprintf (stderr, "FAILED: result: \"%s\"\n" \
     38              "        expected: NULL\n",
     39              actual);
     40     return 0;
     41   }
     42   if (0 != strcmp (actual, expected))
     43   {
     44     fprintf (stderr, "FAILED: result: \"%s\"\n" \
     45              "        expected: \"%s\"\n",
     46              actual, expected);
     47     return 0;
     48   }
     49   return ! 0;
     50 }
     51 
     52 
     53 int
     54 main (int argc,
     55       char *const *argv)
     56 {
     57   struct MHD_Response *r;
     58   (void) argc;
     59   (void) argv; /* Unused. Silence compiler warning. */
     60 
     61   r = MHD_create_response_empty (MHD_RF_NONE);
     62   if (NULL == r)
     63   {
     64     fprintf (stderr, "Cannot create a response.\n");
     65     return 1;
     66   }
     67 
     68   /* ** Test basic header functions ** */
     69 
     70   /* Add first header */
     71   if (MHD_YES != MHD_add_response_header (r, "Header-Type-A", "value-a1"))
     72   {
     73     fprintf (stderr, "Cannot add header A1.\n");
     74     MHD_destroy_response (r);
     75     return 2;
     76   }
     77   if (! expect_str (MHD_get_response_header (r, "Header-Type-A"), "value-a1"))
     78   {
     79     MHD_destroy_response (r);
     80     return 2;
     81   }
     82   /* Add second header with the same name */
     83   if (MHD_YES != MHD_add_response_header (r, "Header-Type-A", "value-a2"))
     84   {
     85     fprintf (stderr, "Cannot add header A2.\n");
     86     MHD_destroy_response (r);
     87     return 2;
     88   }
     89   /* Value of the first header must be returned */
     90   if (! expect_str (MHD_get_response_header (r, "Header-Type-A"), "value-a1"))
     91   {
     92     MHD_destroy_response (r);
     93     return 2;
     94   }
     95   /* Remove the first header */
     96   if (MHD_YES != MHD_del_response_header (r, "Header-Type-A", "value-a1"))
     97   {
     98     fprintf (stderr, "Cannot remove header A1.\n");
     99     MHD_destroy_response (r);
    100     return 2;
    101   }
    102   /* Value of the ex-second header must be returned */
    103   if (! expect_str (MHD_get_response_header (r, "Header-Type-A"), "value-a2"))
    104   {
    105     MHD_destroy_response (r);
    106     return 2;
    107   }
    108   if (MHD_YES != MHD_add_response_header (r, "Header-Type-A", "value-a3"))
    109   {
    110     fprintf (stderr, "Cannot add header A2.\n");
    111     MHD_destroy_response (r);
    112     return 2;
    113   }
    114   /* Value of the ex-second header must be returned */
    115   if (! expect_str (MHD_get_response_header (r, "Header-Type-A"), "value-a2"))
    116   {
    117     MHD_destroy_response (r);
    118     return 2;
    119   }
    120   /* Remove the last header */
    121   if (MHD_YES != MHD_del_response_header (r, "Header-Type-A", "value-a3"))
    122   {
    123     fprintf (stderr, "Cannot add header A2.\n");
    124     MHD_destroy_response (r);
    125     return 2;
    126   }
    127   if (! expect_str (MHD_get_response_header (r, "Header-Type-A"), "value-a2"))
    128   {
    129     MHD_destroy_response (r);
    130     return 2;
    131   }
    132   if (! expect_str (MHD_get_response_header (r, "Header-Type-B"), NULL))
    133   {
    134     MHD_destroy_response (r);
    135     return 2;
    136   }
    137   if (MHD_NO != MHD_del_response_header (r, "Header-Type-C", "value-a3"))
    138   {
    139     fprintf (stderr, "Removed non-existing header.\n");
    140     MHD_destroy_response (r);
    141     return 2;
    142   }
    143   if (MHD_NO != MHD_del_response_header (r, "Header-Type-A", "value-c"))
    144   {
    145     fprintf (stderr, "Removed non-existing header value.\n");
    146     MHD_destroy_response (r);
    147     return 2;
    148   }
    149 
    150   if ((MHD_YES != MHD_add_response_header (r, "Empty-Header", "")) ||
    151       (! expect_str (MHD_get_response_header (r, "Empty-Header"), "")) ||
    152       (MHD_YES != MHD_del_response_header (r, "Empty-Header", "")) ||
    153       (! expect_str (MHD_get_response_header (r, "Empty-Header"), NULL)))
    154   {
    155     fprintf (stderr, "Cannot handle a response header with an empty value.\n");
    156     MHD_destroy_response (r);
    157     return 2;
    158   }
    159   if ((MHD_YES != MHD_add_response_footer (r, "Empty-Footer", "")) ||
    160       (! expect_str (MHD_get_response_header (r, "Empty-Footer"), "")) ||
    161       (MHD_YES != MHD_del_response_header (r, "Empty-Footer", "")) ||
    162       (! expect_str (MHD_get_response_header (r, "Empty-Footer"), NULL)))
    163   {
    164     fprintf (stderr, "Cannot handle a response footer with an empty value.\n");
    165     MHD_destroy_response (r);
    166     return 2;
    167   }
    168   if ((MHD_NO != MHD_add_response_header (r, "", "value")) ||
    169       (MHD_NO != MHD_add_response_footer (r, "", "value")))
    170   {
    171     fprintf (stderr, "Accepted a response field with an empty name.\n");
    172     MHD_destroy_response (r);
    173     return 2;
    174   }
    175 
    176   /* ** Test "Connection:" header ** */
    177 
    178   if ((MHD_NO != MHD_add_response_header (r, "Connection", "")) ||
    179       (! expect_str (MHD_get_response_header (r, "Connection"), NULL)))
    180   {
    181     fprintf (stderr, "Accepted an empty \"Connection\" header value.\n");
    182     MHD_destroy_response (r);
    183     return 3;
    184   }
    185   if (MHD_YES != MHD_add_response_header (r, "Connection", "a,b,c,d,e"))
    186   {
    187     fprintf (stderr, "Cannot add \"Connection\" header with simple values.\n");
    188     MHD_destroy_response (r);
    189     return 3;
    190   }
    191   if (! expect_str (MHD_get_response_header (r, "Connection"), "a, b, c, d, e"))
    192   {
    193     MHD_destroy_response (r);
    194     return 3;
    195   }
    196   if ((MHD_NO != MHD_add_response_header (r, "Connection", "")) ||
    197       (! expect_str (MHD_get_response_header (r, "Connection"),
    198                      "a, b, c, d, e")))
    199   {
    200     fprintf (stderr, "Accepted an empty value for existing "
    201              "\"Connection\" header.\n");
    202     MHD_destroy_response (r);
    203     return 3;
    204   }
    205   if (MHD_YES != MHD_del_response_header (r, "Connection", "e,b,c,d,a"))
    206   {
    207     fprintf (stderr,
    208              "Cannot remove \"Connection\" header with simple values.\n");
    209     MHD_destroy_response (r);
    210     return 3;
    211   }
    212   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    213   {
    214     MHD_destroy_response (r);
    215     return 3;
    216   }
    217 
    218   if (MHD_YES != MHD_add_response_header (r, "Connection",
    219                                           "i,k,l,m,n,o,p,close"))
    220   {
    221     fprintf (stderr,
    222              "Cannot add \"Connection\" header with simple values and \"close\".\n");
    223     MHD_destroy_response (r);
    224     return 3;
    225   }
    226   if (! expect_str (MHD_get_response_header (r, "Connection"),
    227                     "close, i, k, l, m, n, o, p"))
    228   {
    229     MHD_destroy_response (r);
    230     return 3;
    231   }
    232   if (MHD_YES != MHD_del_response_header (r, "Connection",
    233                                           "i,k,l,m,n,o,p,close"))
    234   {
    235     fprintf (stderr,
    236              "Cannot remove \"Connection\" header with simple values and \"close\".\n");
    237     MHD_destroy_response (r);
    238     return 3;
    239   }
    240   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    241   {
    242     MHD_destroy_response (r);
    243     return 3;
    244   }
    245 
    246   if (MHD_YES != MHD_add_response_header (r, "Connection",
    247                                           "1,2,3,4,5,6,7,close"))
    248   {
    249     fprintf (stderr,
    250              "Cannot add \"Connection\" header with simple values and \"close\".\n");
    251     MHD_destroy_response (r);
    252     return 3;
    253   }
    254   if (! expect_str (MHD_get_response_header (r, "Connection"),
    255                     "close, 1, 2, 3, 4, 5, 6, 7"))
    256   {
    257     MHD_destroy_response (r);
    258     return 3;
    259   }
    260   if (MHD_YES != MHD_add_response_header (r, "Connection", "8,9,close"))
    261   {
    262     fprintf (stderr,
    263              "Cannot add second \"Connection\" header with simple values and \"close\".\n");
    264     MHD_destroy_response (r);
    265     return 3;
    266   }
    267   if (! expect_str (MHD_get_response_header (r, "Connection"),
    268                     "close, 1, 2, 3, 4, 5, 6, 7, 8, 9"))
    269   {
    270     MHD_destroy_response (r);
    271     return 3;
    272   }
    273   if (MHD_YES != MHD_del_response_header (r, "Connection", "1,3,5,7,9"))
    274   {
    275     fprintf (stderr,
    276              "Cannot remove part of \"Connection\" header with simple values.\n");
    277     MHD_destroy_response (r);
    278     return 3;
    279   }
    280   if (! expect_str (MHD_get_response_header (r, "Connection"),
    281                     "close, 2, 4, 6, 8"))
    282   {
    283     MHD_destroy_response (r);
    284     return 3;
    285   }
    286   if (MHD_YES != MHD_add_response_header (r, "Connection", "10,12"))
    287   {
    288     fprintf (stderr,
    289              "Cannot add third \"Connection\" header with simple values.\n");
    290     MHD_destroy_response (r);
    291     return 3;
    292   }
    293   if (! expect_str (MHD_get_response_header (r, "Connection"),
    294                     "close, 2, 4, 6, 8, 10, 12"))
    295   {
    296     MHD_destroy_response (r);
    297     return 3;
    298   }
    299   if (MHD_YES != MHD_del_response_header (r, "Connection",
    300                                           "12  ,10  ,8  ,close"))
    301   {
    302     fprintf (stderr,
    303              "Cannot remove part of \"Connection\" header with simple values and \"close\".\n");
    304     MHD_destroy_response (r);
    305     return 3;
    306   }
    307   if (! expect_str (MHD_get_response_header (r, "Connection"), "2, 4, 6"))
    308   {
    309     MHD_destroy_response (r);
    310     return 3;
    311   }
    312   if (MHD_YES != MHD_add_response_header (r, "Connection", "close"))
    313   {
    314     fprintf (stderr, "Cannot add \"Connection\" header with \"close\" only.\n");
    315     MHD_destroy_response (r);
    316     return 3;
    317   }
    318   if (! expect_str (MHD_get_response_header (r, "Connection"),
    319                     "close, 2, 4, 6"))
    320   {
    321     MHD_destroy_response (r);
    322     return 3;
    323   }
    324   if (MHD_YES != MHD_del_response_header (r, "Connection", "4  ,5,6,7  8,"))
    325   {
    326     fprintf (stderr,
    327              "Cannot remove part of \"Connection\" header with simple values and non-existing tokens.\n");
    328     MHD_destroy_response (r);
    329     return 3;
    330   }
    331   if (! expect_str (MHD_get_response_header (r, "Connection"), "close, 2"))
    332   {
    333     MHD_destroy_response (r);
    334     return 3;
    335   }
    336   if (MHD_YES != MHD_add_response_header (r, "Connection", "close"))
    337   {
    338     fprintf (stderr, "Cannot add \"Connection\" header with \"close\" only.\n");
    339     MHD_destroy_response (r);
    340     return 3;
    341   }
    342   if (! expect_str (MHD_get_response_header (r, "Connection"), "close, 2"))
    343   {
    344     MHD_destroy_response (r);
    345     return 3;
    346   }
    347   if (MHD_YES != MHD_del_response_header (r, "Connection",
    348                                           "close, 10, 12, 22, nothing"))
    349   {
    350     fprintf (stderr,
    351              "Cannot remove part of \"Connection\" header with \"close\" and non-existing tokens.\n");
    352     MHD_destroy_response (r);
    353     return 3;
    354   }
    355   if (! expect_str (MHD_get_response_header (r, "Connection"), "2"))
    356   {
    357     MHD_destroy_response (r);
    358     return 3;
    359   }
    360   if (MHD_YES != MHD_del_response_header (r, "Connection", "2"))
    361   {
    362     fprintf (stderr,
    363              "Cannot remove part of \"Connection\" header with simple values and non-existing tokens.\n");
    364     MHD_destroy_response (r);
    365     return 3;
    366   }
    367   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    368   {
    369     MHD_destroy_response (r);
    370     return 3;
    371   }
    372   if (MHD_YES != MHD_add_response_header (r, "Connection", "close"))
    373   {
    374     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    375     MHD_destroy_response (r);
    376     return 3;
    377   }
    378   if (! expect_str (MHD_get_response_header (r, "Connection"), "close"))
    379   {
    380     MHD_destroy_response (r);
    381     return 3;
    382   }
    383   if (MHD_YES != MHD_add_response_header (r, "Connection", "close"))
    384   {
    385     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    386     MHD_destroy_response (r);
    387     return 3;
    388   }
    389   if (! expect_str (MHD_get_response_header (r, "Connection"), "close"))
    390   {
    391     MHD_destroy_response (r);
    392     return 3;
    393   }
    394   if (MHD_YES != MHD_del_response_header (r, "Connection", "close"))
    395   {
    396     fprintf (stderr, "Cannot remove \"Connection\" header with \"close\".\n");
    397     MHD_destroy_response (r);
    398     return 3;
    399   }
    400   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    401   {
    402     MHD_destroy_response (r);
    403     return 3;
    404   }
    405 
    406   if (MHD_YES != MHD_add_response_header (r, "Connection", "close,other-token"))
    407   {
    408     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    409     MHD_destroy_response (r);
    410     return 3;
    411   }
    412   if (! expect_str (MHD_get_response_header (r, "Connection"),
    413                     "close, other-token"))
    414   {
    415     MHD_destroy_response (r);
    416     return 3;
    417   }
    418   if (MHD_YES != MHD_add_response_header (r, "Connection", "close, new-token"))
    419   {
    420     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    421     MHD_destroy_response (r);
    422     return 3;
    423   }
    424   if (! expect_str (MHD_get_response_header (r, "Connection"),
    425                     "close, other-token, new-token"))
    426   {
    427     MHD_destroy_response (r);
    428     return 3;
    429   }
    430   if (MHD_YES != MHD_del_response_header (r, "Connection", "close, new-token"))
    431   {
    432     fprintf (stderr, "Cannot remove tokens from \"Connection\".\n");
    433     MHD_destroy_response (r);
    434     return 3;
    435   }
    436   if (! expect_str (MHD_get_response_header (r, "Connection"), "other-token"))
    437   {
    438     MHD_destroy_response (r);
    439     return 3;
    440   }
    441   if (MHD_YES != MHD_del_response_header (r, "Connection", "other-token"))
    442   {
    443     fprintf (stderr, "Cannot remove tokens from \"Connection\".\n");
    444     MHD_destroy_response (r);
    445     return 3;
    446   }
    447   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    448   {
    449     MHD_destroy_response (r);
    450     return 3;
    451   }
    452 
    453   if (MHD_YES != MHD_add_response_header (r, "Connection",
    454                                           "close, one-long-token"))
    455   {
    456     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    457     MHD_destroy_response (r);
    458     return 3;
    459   }
    460   if (! expect_str (MHD_get_response_header (r, "Connection"),
    461                     "close, one-long-token"))
    462   {
    463     MHD_destroy_response (r);
    464     return 3;
    465   }
    466   if (MHD_YES != MHD_add_response_header (r, "Connection", "close"))
    467   {
    468     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    469     MHD_destroy_response (r);
    470     return 3;
    471   }
    472   if (! expect_str (MHD_get_response_header (r, "Connection"),
    473                     "close, one-long-token"))
    474   {
    475     MHD_destroy_response (r);
    476     return 3;
    477   }
    478   if (MHD_YES != MHD_del_response_header (r, "Connection",
    479                                           "one-long-token,close"))
    480   {
    481     fprintf (stderr, "Cannot remove tokens from \"Connection\".\n");
    482     MHD_destroy_response (r);
    483     return 3;
    484   }
    485   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    486   {
    487     MHD_destroy_response (r);
    488     return 3;
    489   }
    490 
    491   if (MHD_YES != MHD_add_response_header (r, "Connection", "close"))
    492   {
    493     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    494     MHD_destroy_response (r);
    495     return 3;
    496   }
    497   if (! expect_str (MHD_get_response_header (r, "Connection"), "close"))
    498   {
    499     MHD_destroy_response (r);
    500     return 3;
    501   }
    502   if (MHD_YES != MHD_add_response_header (r, "Connection",
    503                                           "close, additional-token"))
    504   {
    505     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    506     MHD_destroy_response (r);
    507     return 3;
    508   }
    509   if (! expect_str (MHD_get_response_header (r, "Connection"),
    510                     "close, additional-token"))
    511   {
    512     MHD_destroy_response (r);
    513     return 3;
    514   }
    515   if (MHD_YES != MHD_del_response_header (r, "Connection",
    516                                           "additional-token,close"))
    517   {
    518     fprintf (stderr, "Cannot remove tokens from \"Connection\".\n");
    519     MHD_destroy_response (r);
    520     return 3;
    521   }
    522   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    523   {
    524     MHD_destroy_response (r);
    525     return 3;
    526   }
    527 
    528 
    529   if (MHD_YES != MHD_add_response_header (r, "Connection", "token-1,token-2"))
    530   {
    531     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    532     MHD_destroy_response (r);
    533     return 3;
    534   }
    535   if (! expect_str (MHD_get_response_header (r, "Connection"),
    536                     "token-1, token-2"))
    537   {
    538     MHD_destroy_response (r);
    539     return 3;
    540   }
    541   if (MHD_YES != MHD_add_response_header (r, "Connection", "token-3"))
    542   {
    543     fprintf (stderr, "Cannot add \"Connection\" header.\n");
    544     MHD_destroy_response (r);
    545     return 3;
    546   }
    547   if (! expect_str (MHD_get_response_header (r, "Connection"),
    548                     "token-1, token-2, token-3"))
    549   {
    550     MHD_destroy_response (r);
    551     return 3;
    552   }
    553   if (MHD_YES != MHD_add_response_header (r, "Connection", "close"))
    554   {
    555     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    556     MHD_destroy_response (r);
    557     return 3;
    558   }
    559   if (! expect_str (MHD_get_response_header (r, "Connection"),
    560                     "close, token-1, token-2, token-3"))
    561   {
    562     MHD_destroy_response (r);
    563     return 3;
    564   }
    565   if (MHD_YES != MHD_add_response_header (r, "Connection", "close"))
    566   {
    567     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    568     MHD_destroy_response (r);
    569     return 3;
    570   }
    571   if (! expect_str (MHD_get_response_header (r, "Connection"),
    572                     "close, token-1, token-2, token-3"))
    573   {
    574     MHD_destroy_response (r);
    575     return 3;
    576   }
    577   if (MHD_YES != MHD_add_response_header (r, "Connection", "close, token-4"))
    578   {
    579     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    580     MHD_destroy_response (r);
    581     return 3;
    582   }
    583   if (! expect_str (MHD_get_response_header (r, "Connection"),
    584                     "close, token-1, token-2, token-3, token-4"))
    585   {
    586     MHD_destroy_response (r);
    587     return 3;
    588   }
    589   if (MHD_YES != MHD_del_response_header (r, "Connection", "close"))
    590   {
    591     fprintf (stderr, "Cannot remove tokens from \"Connection\".\n");
    592     MHD_destroy_response (r);
    593     return 3;
    594   }
    595   if (! expect_str (MHD_get_response_header (r, "Connection"),
    596                     "token-1, token-2, token-3, token-4"))
    597   {
    598     MHD_destroy_response (r);
    599     return 3;
    600   }
    601   if (MHD_YES != MHD_add_response_header (r, "Connection", "close, token-5"))
    602   {
    603     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    604     MHD_destroy_response (r);
    605     return 3;
    606   }
    607   if (! expect_str (MHD_get_response_header (r, "Connection"),
    608                     "close, token-1, token-2, token-3, token-4, token-5"))
    609   {
    610     MHD_destroy_response (r);
    611     return 3;
    612   }
    613   if (MHD_NO != MHD_del_response_header (r, "Connection",
    614                                          "non-existing, token-9"))
    615   {
    616     fprintf (stderr,
    617              "Non-existing tokens successfully removed from \"Connection\" header.\n");
    618     MHD_destroy_response (r);
    619     return 3;
    620   }
    621   if (! expect_str (MHD_get_response_header (r, "Connection"),
    622                     "close, token-1, token-2, token-3, token-4, token-5"))
    623   {
    624     MHD_destroy_response (r);
    625     return 3;
    626   }
    627   if (MHD_NO != MHD_add_response_header (r, "Connection",
    628                                          ",,,,,,,,,,,,    ,\t\t\t, , , "))
    629   {
    630     fprintf (stderr,
    631              "Empty token was added successfully to \"Connection\" header.\n");
    632     MHD_destroy_response (r);
    633     return 3;
    634   }
    635   if (MHD_YES != MHD_del_response_header (r, "Connection",
    636                                           "close, token-1, token-2, token-3, token-4, token-5"))
    637   {
    638     fprintf (stderr, "Cannot remove tokens from \"Connection\".\n");
    639     MHD_destroy_response (r);
    640     return 3;
    641   }
    642   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    643   {
    644     MHD_destroy_response (r);
    645     return 3;
    646   }
    647   if (MHD_NO != MHD_add_response_header (r, "Connection",
    648                                          ",,,,,,,,,,,,    ,\t\t\t, , , "))
    649   {
    650     fprintf (stderr,
    651              "Empty token was added successfully to \"Connection\" header.\n");
    652     MHD_destroy_response (r);
    653     return 3;
    654   }
    655   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    656   {
    657     MHD_destroy_response (r);
    658     return 3;
    659   }
    660 
    661   if (MHD_NO != MHD_add_response_header (r, "Connection", "keep-Alive"))
    662   {
    663     fprintf (stderr,
    664              "Successfully added \"Connection\" header with \"keep-Alive\".\n");
    665     MHD_destroy_response (r);
    666     return 4;
    667   }
    668   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    669   {
    670     MHD_destroy_response (r);
    671     return 4;
    672   }
    673   if (MHD_YES != MHD_add_response_header (r, "Connection", "keep-Alive, Close"))
    674   {
    675     fprintf (stderr,
    676              "Cannot add \"Connection\" header with \"keep-Alive, Close\".\n");
    677     MHD_destroy_response (r);
    678     return 4;
    679   }
    680   if (! expect_str (MHD_get_response_header (r, "Connection"), "close"))
    681   {
    682     MHD_destroy_response (r);
    683     return 4;
    684   }
    685   if (MHD_NO != MHD_add_response_header (r, "Connection", "keep-Alive"))
    686   {
    687     fprintf (stderr,
    688              "Successfully added \"Connection\" header with \"keep-Alive\".\n");
    689     MHD_destroy_response (r);
    690     return 4;
    691   }
    692   if (MHD_YES != MHD_add_response_header (r, "Connection", "keep-Alive, Close"))
    693   {
    694     fprintf (stderr,
    695              "Cannot add \"Connection\" header with \"keep-Alive, Close\".\n");
    696     MHD_destroy_response (r);
    697     return 4;
    698   }
    699   if (! expect_str (MHD_get_response_header (r, "Connection"), "close"))
    700   {
    701     MHD_destroy_response (r);
    702     return 4;
    703   }
    704   if (MHD_YES != MHD_add_response_header (r, "Connection",
    705                                           "close, additional-token"))
    706   {
    707     fprintf (stderr, "Cannot add \"Connection\" header with "
    708              "\"close, additional-token\".\n");
    709     MHD_destroy_response (r);
    710     return 4;
    711   }
    712   if (! expect_str (MHD_get_response_header (r, "Connection"),
    713                     "close, additional-token"))
    714   {
    715     MHD_destroy_response (r);
    716     return 4;
    717   }
    718   if (MHD_NO != MHD_add_response_header (r, "Connection", "keep-Alive"))
    719   {
    720     fprintf (stderr,
    721              "Successfully added \"Connection\" header with \"keep-Alive\".\n");
    722     MHD_destroy_response (r);
    723     return 4;
    724   }
    725   if (! expect_str (MHD_get_response_header (r, "Connection"),
    726                     "close, additional-token"))
    727   {
    728     MHD_destroy_response (r);
    729     return 4;
    730   }
    731   if (MHD_YES != MHD_del_response_header (r, "Connection",
    732                                           "additional-token,close"))
    733   {
    734     fprintf (stderr, "Cannot remove tokens from \"Connection\".\n");
    735     MHD_destroy_response (r);
    736     return 4;
    737   }
    738   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    739   {
    740     MHD_destroy_response (r);
    741     return 4;
    742   }
    743 
    744   if (MHD_YES != MHD_add_response_header (r, "Connection",
    745                                           "Keep-aLive, token-1"))
    746   {
    747     fprintf (stderr,
    748              "Cannot add \"Connection\" header with \"Keep-aLive, token-1\".\n")
    749     ;
    750     MHD_destroy_response (r);
    751     return 4;
    752   }
    753   if (! expect_str (MHD_get_response_header (r, "Connection"), "token-1"))
    754   {
    755     MHD_destroy_response (r);
    756     return 4;
    757   }
    758   if (MHD_YES != MHD_add_response_header (r, "Connection",
    759                                           "Keep-aLive, token-2"))
    760   {
    761     fprintf (stderr,
    762              "Cannot add \"Connection\" header with \"Keep-aLive, token-2\".\n")
    763     ;
    764     MHD_destroy_response (r);
    765     return 4;
    766   }
    767   if (! expect_str (MHD_get_response_header (r, "Connection"),
    768                     "token-1, token-2"))
    769   {
    770     MHD_destroy_response (r);
    771     return 4;
    772   }
    773   if (MHD_YES != MHD_add_response_header (r, "Connection",
    774                                           "Keep-aLive, token-3, close"))
    775   {
    776     fprintf (stderr,
    777              "Cannot add \"Connection\" header with \"Keep-aLive, token-3, close\".\n");
    778     MHD_destroy_response (r);
    779     return 4;
    780   }
    781   if (! expect_str (MHD_get_response_header (r, "Connection"),
    782                     "close, token-1, token-2, token-3"))
    783   {
    784     MHD_destroy_response (r);
    785     return 4;
    786   }
    787   if (MHD_YES != MHD_del_response_header (r, "Connection",
    788                                           "close"))
    789   {
    790     fprintf (stderr, "Cannot remove \"close\" tokens from \"Connection\".\n");
    791     MHD_destroy_response (r);
    792     return 4;
    793   }
    794   if (! expect_str (MHD_get_response_header (r, "Connection"),
    795                     "token-1, token-2, token-3"))
    796   {
    797     MHD_destroy_response (r);
    798     return 4;
    799   }
    800   if (MHD_YES != MHD_add_response_header (r, "Connection", "Keep-aLive, close"))
    801   {
    802     fprintf (stderr,
    803              "Cannot add \"Connection\" header with \"Keep-aLive, token-3, close\".\n");
    804     MHD_destroy_response (r);
    805     return 4;
    806   }
    807   if (! expect_str (MHD_get_response_header (r, "Connection"),
    808                     "close, token-1, token-2, token-3"))
    809   {
    810     MHD_destroy_response (r);
    811     return 4;
    812   }
    813   if (MHD_YES != MHD_del_response_header (r, "Connection",
    814                                           "close, token-1, Keep-Alive, token-2, token-3"))
    815   {
    816     fprintf (stderr, "Cannot remove \"close\" tokens from \"Connection\".\n");
    817     MHD_destroy_response (r);
    818     return 4;
    819   }
    820   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    821   {
    822     MHD_destroy_response (r);
    823     return 4;
    824   }
    825 
    826   if (MHD_YES != MHD_add_response_header (r, "Date",
    827                                           "Wed, 01 Apr 2015 00:00:00 GMT"))
    828   {
    829     fprintf (stderr,
    830              "Cannot add \"Date\" header with \"Wed, 01 Apr 2015 00:00:00 GMT\".\n");
    831     MHD_destroy_response (r);
    832     return 5;
    833   }
    834   if (MHD_NO != MHD_add_response_header (r, "Date", ""))
    835   {
    836     fprintf (stderr, "Accepted an empty \"Date\" header value.\n");
    837     MHD_destroy_response (r);
    838     return 5;
    839   }
    840   if (! expect_str (MHD_get_response_header (r, "Date"),
    841                     "Wed, 01 Apr 2015 00:00:00 GMT"))
    842   {
    843     MHD_destroy_response (r);
    844     return 5;
    845   }
    846   if (MHD_YES != MHD_add_response_header (r, "Date",
    847                                           "Thu, 01 Apr 2021 00:00:00 GMT"))
    848   {
    849     fprintf (stderr,
    850              "Cannot add \"Date\" header with \"Thu, 01 Apr 2021 00:00:00 GMT\".\n");
    851     MHD_destroy_response (r);
    852     return 5;
    853   }
    854   if (! expect_str (MHD_get_response_header (r, "Date"),
    855                     "Thu, 01 Apr 2021 00:00:00 GMT"))
    856   {
    857     MHD_destroy_response (r);
    858     return 5;
    859   }
    860   if (MHD_YES != MHD_del_response_header (r, "Date",
    861                                           "Thu, 01 Apr 2021 00:00:00 GMT"))
    862   {
    863     fprintf (stderr, "Cannot remove \"Date\" header.\n");
    864     MHD_destroy_response (r);
    865     return 5;
    866   }
    867   if (! expect_str (MHD_get_response_header (r, "Date"), NULL))
    868   {
    869     MHD_destroy_response (r);
    870     return 5;
    871   }
    872 
    873   if (MHD_YES != MHD_add_response_header (r, MHD_HTTP_HEADER_TRANSFER_ENCODING,
    874                                           "chunked"))
    875   {
    876     fprintf (stderr,
    877              "Cannot add \"" MHD_HTTP_HEADER_TRANSFER_ENCODING \
    878              "\" header with \"chunked\".\n");
    879     MHD_destroy_response (r);
    880     return 6;
    881   }
    882   if (! expect_str (MHD_get_response_header (r,
    883                                              MHD_HTTP_HEADER_TRANSFER_ENCODING),
    884                     "chunked"))
    885   {
    886     MHD_destroy_response (r);
    887     return 6;
    888   }
    889   if (MHD_YES != MHD_add_response_header (r, MHD_HTTP_HEADER_TRANSFER_ENCODING,
    890                                           "chunked"))
    891   {
    892     fprintf (stderr,
    893              "Cannot add \"" MHD_HTTP_HEADER_TRANSFER_ENCODING \
    894              "\" second header with \"chunked\".\n");
    895     MHD_destroy_response (r);
    896     return 6;
    897   }
    898   if (! expect_str (MHD_get_response_header (r,
    899                                              MHD_HTTP_HEADER_TRANSFER_ENCODING),
    900                     "chunked"))
    901   {
    902     MHD_destroy_response (r);
    903     return 6;
    904   }
    905   if (MHD_NO != MHD_add_response_header (r, MHD_HTTP_HEADER_TRANSFER_ENCODING,
    906                                          ""))
    907   {
    908     fprintf (stderr,
    909              "Successfully added \"" MHD_HTTP_HEADER_TRANSFER_ENCODING \
    910              "\" header with an empty value.\n");
    911     MHD_destroy_response (r);
    912     return 6;
    913   }
    914   if (MHD_NO != MHD_add_response_header (r, MHD_HTTP_HEADER_TRANSFER_ENCODING,
    915                                          "identity"))
    916   {
    917     fprintf (stderr,
    918              "Successfully added \"" MHD_HTTP_HEADER_TRANSFER_ENCODING \
    919              "\" header with \"identity\".\n");
    920     MHD_destroy_response (r);
    921     return 6;
    922   }
    923   if (! expect_str (MHD_get_response_header (r,
    924                                              MHD_HTTP_HEADER_TRANSFER_ENCODING),
    925                     "chunked"))
    926   {
    927     MHD_destroy_response (r);
    928     return 6;
    929   }
    930   if (MHD_YES != MHD_del_response_header (r, MHD_HTTP_HEADER_TRANSFER_ENCODING,
    931                                           "chunked"))
    932   {
    933     fprintf (stderr, "Cannot remove \"" MHD_HTTP_HEADER_TRANSFER_ENCODING \
    934              "\" header.\n");
    935     MHD_destroy_response (r);
    936     return 6;
    937   }
    938   if (! expect_str (MHD_get_response_header (r,
    939                                              MHD_HTTP_HEADER_TRANSFER_ENCODING),
    940                     NULL))
    941   {
    942     MHD_destroy_response (r);
    943     return 6;
    944   }
    945 
    946   MHD_destroy_response (r);
    947 
    948   r = MHD_create_response_empty (MHD_RF_HEAD_ONLY_RESPONSE);
    949   if (NULL == r)
    950   {
    951     fprintf (stderr, "Cannot create a HEAD-only response.\n");
    952     return 7;
    953   }
    954   if (MHD_NO != MHD_add_response_header (r, MHD_HTTP_HEADER_CONTENT_LENGTH, ""))
    955   {
    956     fprintf (stderr, "Accepted an empty \"Content-Length\" header value.\n");
    957     MHD_destroy_response (r);
    958     return 7;
    959   }
    960   MHD_destroy_response (r);
    961 
    962   printf ("All tests has been successfully passed.\n");
    963   return 0;
    964 }