libmicrohttpd

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

test_response_entries.c (26647B)


      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   /* ** Test "Connection:" header ** */
    151 
    152   if (MHD_YES != MHD_add_response_header (r, "Connection", "a,b,c,d,e"))
    153   {
    154     fprintf (stderr, "Cannot add \"Connection\" header with simple values.\n");
    155     MHD_destroy_response (r);
    156     return 3;
    157   }
    158   if (! expect_str (MHD_get_response_header (r, "Connection"), "a, b, c, d, e"))
    159   {
    160     MHD_destroy_response (r);
    161     return 3;
    162   }
    163   if (MHD_YES != MHD_del_response_header (r, "Connection", "e,b,c,d,a"))
    164   {
    165     fprintf (stderr,
    166              "Cannot remove \"Connection\" header with simple values.\n");
    167     MHD_destroy_response (r);
    168     return 3;
    169   }
    170   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    171   {
    172     MHD_destroy_response (r);
    173     return 3;
    174   }
    175 
    176   if (MHD_YES != MHD_add_response_header (r, "Connection",
    177                                           "i,k,l,m,n,o,p,close"))
    178   {
    179     fprintf (stderr,
    180              "Cannot add \"Connection\" header with simple values and \"close\".\n");
    181     MHD_destroy_response (r);
    182     return 3;
    183   }
    184   if (! expect_str (MHD_get_response_header (r, "Connection"),
    185                     "close, i, k, l, m, n, o, p"))
    186   {
    187     MHD_destroy_response (r);
    188     return 3;
    189   }
    190   if (MHD_YES != MHD_del_response_header (r, "Connection",
    191                                           "i,k,l,m,n,o,p,close"))
    192   {
    193     fprintf (stderr,
    194              "Cannot remove \"Connection\" header with simple values and \"close\".\n");
    195     MHD_destroy_response (r);
    196     return 3;
    197   }
    198   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    199   {
    200     MHD_destroy_response (r);
    201     return 3;
    202   }
    203 
    204   if (MHD_YES != MHD_add_response_header (r, "Connection",
    205                                           "1,2,3,4,5,6,7,close"))
    206   {
    207     fprintf (stderr,
    208              "Cannot add \"Connection\" header with simple values and \"close\".\n");
    209     MHD_destroy_response (r);
    210     return 3;
    211   }
    212   if (! expect_str (MHD_get_response_header (r, "Connection"),
    213                     "close, 1, 2, 3, 4, 5, 6, 7"))
    214   {
    215     MHD_destroy_response (r);
    216     return 3;
    217   }
    218   if (MHD_YES != MHD_add_response_header (r, "Connection", "8,9,close"))
    219   {
    220     fprintf (stderr,
    221              "Cannot add second \"Connection\" header with simple values and \"close\".\n");
    222     MHD_destroy_response (r);
    223     return 3;
    224   }
    225   if (! expect_str (MHD_get_response_header (r, "Connection"),
    226                     "close, 1, 2, 3, 4, 5, 6, 7, 8, 9"))
    227   {
    228     MHD_destroy_response (r);
    229     return 3;
    230   }
    231   if (MHD_YES != MHD_del_response_header (r, "Connection", "1,3,5,7,9"))
    232   {
    233     fprintf (stderr,
    234              "Cannot remove part of \"Connection\" header with simple values.\n");
    235     MHD_destroy_response (r);
    236     return 3;
    237   }
    238   if (! expect_str (MHD_get_response_header (r, "Connection"),
    239                     "close, 2, 4, 6, 8"))
    240   {
    241     MHD_destroy_response (r);
    242     return 3;
    243   }
    244   if (MHD_YES != MHD_add_response_header (r, "Connection", "10,12"))
    245   {
    246     fprintf (stderr,
    247              "Cannot add third \"Connection\" header with simple values.\n");
    248     MHD_destroy_response (r);
    249     return 3;
    250   }
    251   if (! expect_str (MHD_get_response_header (r, "Connection"),
    252                     "close, 2, 4, 6, 8, 10, 12"))
    253   {
    254     MHD_destroy_response (r);
    255     return 3;
    256   }
    257   if (MHD_YES != MHD_del_response_header (r, "Connection",
    258                                           "12  ,10  ,8  ,close"))
    259   {
    260     fprintf (stderr,
    261              "Cannot remove part of \"Connection\" header with simple values and \"close\".\n");
    262     MHD_destroy_response (r);
    263     return 3;
    264   }
    265   if (! expect_str (MHD_get_response_header (r, "Connection"), "2, 4, 6"))
    266   {
    267     MHD_destroy_response (r);
    268     return 3;
    269   }
    270   if (MHD_YES != MHD_add_response_header (r, "Connection", "close"))
    271   {
    272     fprintf (stderr, "Cannot add \"Connection\" header with \"close\" only.\n");
    273     MHD_destroy_response (r);
    274     return 3;
    275   }
    276   if (! expect_str (MHD_get_response_header (r, "Connection"),
    277                     "close, 2, 4, 6"))
    278   {
    279     MHD_destroy_response (r);
    280     return 3;
    281   }
    282   if (MHD_YES != MHD_del_response_header (r, "Connection", "4  ,5,6,7  8,"))
    283   {
    284     fprintf (stderr,
    285              "Cannot remove part of \"Connection\" header with simple values and non-existing tokens.\n");
    286     MHD_destroy_response (r);
    287     return 3;
    288   }
    289   if (! expect_str (MHD_get_response_header (r, "Connection"), "close, 2"))
    290   {
    291     MHD_destroy_response (r);
    292     return 3;
    293   }
    294   if (MHD_YES != MHD_add_response_header (r, "Connection", "close"))
    295   {
    296     fprintf (stderr, "Cannot add \"Connection\" header with \"close\" only.\n");
    297     MHD_destroy_response (r);
    298     return 3;
    299   }
    300   if (! expect_str (MHD_get_response_header (r, "Connection"), "close, 2"))
    301   {
    302     MHD_destroy_response (r);
    303     return 3;
    304   }
    305   if (MHD_YES != MHD_del_response_header (r, "Connection",
    306                                           "close, 10, 12, 22, nothing"))
    307   {
    308     fprintf (stderr,
    309              "Cannot remove part of \"Connection\" header with \"close\" and non-existing tokens.\n");
    310     MHD_destroy_response (r);
    311     return 3;
    312   }
    313   if (! expect_str (MHD_get_response_header (r, "Connection"), "2"))
    314   {
    315     MHD_destroy_response (r);
    316     return 3;
    317   }
    318   if (MHD_YES != MHD_del_response_header (r, "Connection", "2"))
    319   {
    320     fprintf (stderr,
    321              "Cannot remove part of \"Connection\" header with simple values and non-existing tokens.\n");
    322     MHD_destroy_response (r);
    323     return 3;
    324   }
    325   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    326   {
    327     MHD_destroy_response (r);
    328     return 3;
    329   }
    330   if (MHD_YES != MHD_add_response_header (r, "Connection", "close"))
    331   {
    332     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    333     MHD_destroy_response (r);
    334     return 3;
    335   }
    336   if (! expect_str (MHD_get_response_header (r, "Connection"), "close"))
    337   {
    338     MHD_destroy_response (r);
    339     return 3;
    340   }
    341   if (MHD_YES != MHD_add_response_header (r, "Connection", "close"))
    342   {
    343     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    344     MHD_destroy_response (r);
    345     return 3;
    346   }
    347   if (! expect_str (MHD_get_response_header (r, "Connection"), "close"))
    348   {
    349     MHD_destroy_response (r);
    350     return 3;
    351   }
    352   if (MHD_YES != MHD_del_response_header (r, "Connection", "close"))
    353   {
    354     fprintf (stderr, "Cannot remove \"Connection\" header with \"close\".\n");
    355     MHD_destroy_response (r);
    356     return 3;
    357   }
    358   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    359   {
    360     MHD_destroy_response (r);
    361     return 3;
    362   }
    363 
    364   if (MHD_YES != MHD_add_response_header (r, "Connection", "close,other-token"))
    365   {
    366     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    367     MHD_destroy_response (r);
    368     return 3;
    369   }
    370   if (! expect_str (MHD_get_response_header (r, "Connection"),
    371                     "close, other-token"))
    372   {
    373     MHD_destroy_response (r);
    374     return 3;
    375   }
    376   if (MHD_YES != MHD_add_response_header (r, "Connection", "close, new-token"))
    377   {
    378     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    379     MHD_destroy_response (r);
    380     return 3;
    381   }
    382   if (! expect_str (MHD_get_response_header (r, "Connection"),
    383                     "close, other-token, new-token"))
    384   {
    385     MHD_destroy_response (r);
    386     return 3;
    387   }
    388   if (MHD_YES != MHD_del_response_header (r, "Connection", "close, new-token"))
    389   {
    390     fprintf (stderr, "Cannot remove tokens from \"Connection\".\n");
    391     MHD_destroy_response (r);
    392     return 3;
    393   }
    394   if (! expect_str (MHD_get_response_header (r, "Connection"), "other-token"))
    395   {
    396     MHD_destroy_response (r);
    397     return 3;
    398   }
    399   if (MHD_YES != MHD_del_response_header (r, "Connection", "other-token"))
    400   {
    401     fprintf (stderr, "Cannot remove tokens from \"Connection\".\n");
    402     MHD_destroy_response (r);
    403     return 3;
    404   }
    405   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    406   {
    407     MHD_destroy_response (r);
    408     return 3;
    409   }
    410 
    411   if (MHD_YES != MHD_add_response_header (r, "Connection",
    412                                           "close, one-long-token"))
    413   {
    414     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    415     MHD_destroy_response (r);
    416     return 3;
    417   }
    418   if (! expect_str (MHD_get_response_header (r, "Connection"),
    419                     "close, one-long-token"))
    420   {
    421     MHD_destroy_response (r);
    422     return 3;
    423   }
    424   if (MHD_YES != MHD_add_response_header (r, "Connection", "close"))
    425   {
    426     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    427     MHD_destroy_response (r);
    428     return 3;
    429   }
    430   if (! expect_str (MHD_get_response_header (r, "Connection"),
    431                     "close, one-long-token"))
    432   {
    433     MHD_destroy_response (r);
    434     return 3;
    435   }
    436   if (MHD_YES != MHD_del_response_header (r, "Connection",
    437                                           "one-long-token,close"))
    438   {
    439     fprintf (stderr, "Cannot remove tokens from \"Connection\".\n");
    440     MHD_destroy_response (r);
    441     return 3;
    442   }
    443   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    444   {
    445     MHD_destroy_response (r);
    446     return 3;
    447   }
    448 
    449   if (MHD_YES != MHD_add_response_header (r, "Connection", "close"))
    450   {
    451     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    452     MHD_destroy_response (r);
    453     return 3;
    454   }
    455   if (! expect_str (MHD_get_response_header (r, "Connection"), "close"))
    456   {
    457     MHD_destroy_response (r);
    458     return 3;
    459   }
    460   if (MHD_YES != MHD_add_response_header (r, "Connection",
    461                                           "close, additional-token"))
    462   {
    463     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    464     MHD_destroy_response (r);
    465     return 3;
    466   }
    467   if (! expect_str (MHD_get_response_header (r, "Connection"),
    468                     "close, additional-token"))
    469   {
    470     MHD_destroy_response (r);
    471     return 3;
    472   }
    473   if (MHD_YES != MHD_del_response_header (r, "Connection",
    474                                           "additional-token,close"))
    475   {
    476     fprintf (stderr, "Cannot remove tokens from \"Connection\".\n");
    477     MHD_destroy_response (r);
    478     return 3;
    479   }
    480   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    481   {
    482     MHD_destroy_response (r);
    483     return 3;
    484   }
    485 
    486 
    487   if (MHD_YES != MHD_add_response_header (r, "Connection", "token-1,token-2"))
    488   {
    489     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    490     MHD_destroy_response (r);
    491     return 3;
    492   }
    493   if (! expect_str (MHD_get_response_header (r, "Connection"),
    494                     "token-1, token-2"))
    495   {
    496     MHD_destroy_response (r);
    497     return 3;
    498   }
    499   if (MHD_YES != MHD_add_response_header (r, "Connection", "token-3"))
    500   {
    501     fprintf (stderr, "Cannot add \"Connection\" header.\n");
    502     MHD_destroy_response (r);
    503     return 3;
    504   }
    505   if (! expect_str (MHD_get_response_header (r, "Connection"),
    506                     "token-1, token-2, token-3"))
    507   {
    508     MHD_destroy_response (r);
    509     return 3;
    510   }
    511   if (MHD_YES != MHD_add_response_header (r, "Connection", "close"))
    512   {
    513     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    514     MHD_destroy_response (r);
    515     return 3;
    516   }
    517   if (! expect_str (MHD_get_response_header (r, "Connection"),
    518                     "close, token-1, token-2, token-3"))
    519   {
    520     MHD_destroy_response (r);
    521     return 3;
    522   }
    523   if (MHD_YES != MHD_add_response_header (r, "Connection", "close"))
    524   {
    525     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    526     MHD_destroy_response (r);
    527     return 3;
    528   }
    529   if (! expect_str (MHD_get_response_header (r, "Connection"),
    530                     "close, token-1, token-2, token-3"))
    531   {
    532     MHD_destroy_response (r);
    533     return 3;
    534   }
    535   if (MHD_YES != MHD_add_response_header (r, "Connection", "close, token-4"))
    536   {
    537     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    538     MHD_destroy_response (r);
    539     return 3;
    540   }
    541   if (! expect_str (MHD_get_response_header (r, "Connection"),
    542                     "close, token-1, token-2, token-3, token-4"))
    543   {
    544     MHD_destroy_response (r);
    545     return 3;
    546   }
    547   if (MHD_YES != MHD_del_response_header (r, "Connection", "close"))
    548   {
    549     fprintf (stderr, "Cannot remove tokens from \"Connection\".\n");
    550     MHD_destroy_response (r);
    551     return 3;
    552   }
    553   if (! expect_str (MHD_get_response_header (r, "Connection"),
    554                     "token-1, token-2, token-3, token-4"))
    555   {
    556     MHD_destroy_response (r);
    557     return 3;
    558   }
    559   if (MHD_YES != MHD_add_response_header (r, "Connection", "close, token-5"))
    560   {
    561     fprintf (stderr, "Cannot add \"Connection\" header with \"close\".\n");
    562     MHD_destroy_response (r);
    563     return 3;
    564   }
    565   if (! expect_str (MHD_get_response_header (r, "Connection"),
    566                     "close, token-1, token-2, token-3, token-4, token-5"))
    567   {
    568     MHD_destroy_response (r);
    569     return 3;
    570   }
    571   if (MHD_NO != MHD_del_response_header (r, "Connection",
    572                                          "non-existing, token-9"))
    573   {
    574     fprintf (stderr,
    575              "Non-existing tokens successfully removed from \"Connection\" header.\n");
    576     MHD_destroy_response (r);
    577     return 3;
    578   }
    579   if (! expect_str (MHD_get_response_header (r, "Connection"),
    580                     "close, token-1, token-2, token-3, token-4, token-5"))
    581   {
    582     MHD_destroy_response (r);
    583     return 3;
    584   }
    585   if (MHD_NO != MHD_add_response_header (r, "Connection",
    586                                          ",,,,,,,,,,,,    ,\t\t\t, , , "))
    587   {
    588     fprintf (stderr,
    589              "Empty token was added successfully to \"Connection\" header.\n");
    590     MHD_destroy_response (r);
    591     return 3;
    592   }
    593   if (MHD_YES != MHD_del_response_header (r, "Connection",
    594                                           "close, token-1, token-2, token-3, token-4, token-5"))
    595   {
    596     fprintf (stderr, "Cannot remove tokens from \"Connection\".\n");
    597     MHD_destroy_response (r);
    598     return 3;
    599   }
    600   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    601   {
    602     MHD_destroy_response (r);
    603     return 3;
    604   }
    605   if (MHD_NO != MHD_add_response_header (r, "Connection",
    606                                          ",,,,,,,,,,,,    ,\t\t\t, , , "))
    607   {
    608     fprintf (stderr,
    609              "Empty token was added successfully to \"Connection\" header.\n");
    610     MHD_destroy_response (r);
    611     return 3;
    612   }
    613   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    614   {
    615     MHD_destroy_response (r);
    616     return 3;
    617   }
    618 
    619   if (MHD_NO != MHD_add_response_header (r, "Connection", "keep-Alive"))
    620   {
    621     fprintf (stderr,
    622              "Successfully added \"Connection\" header with \"keep-Alive\".\n");
    623     MHD_destroy_response (r);
    624     return 4;
    625   }
    626   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    627   {
    628     MHD_destroy_response (r);
    629     return 4;
    630   }
    631   if (MHD_YES != MHD_add_response_header (r, "Connection", "keep-Alive, Close"))
    632   {
    633     fprintf (stderr,
    634              "Cannot add \"Connection\" header with \"keep-Alive, Close\".\n");
    635     MHD_destroy_response (r);
    636     return 4;
    637   }
    638   if (! expect_str (MHD_get_response_header (r, "Connection"), "close"))
    639   {
    640     MHD_destroy_response (r);
    641     return 4;
    642   }
    643   if (MHD_NO != MHD_add_response_header (r, "Connection", "keep-Alive"))
    644   {
    645     fprintf (stderr,
    646              "Successfully added \"Connection\" header with \"keep-Alive\".\n");
    647     MHD_destroy_response (r);
    648     return 4;
    649   }
    650   if (MHD_YES != MHD_add_response_header (r, "Connection", "keep-Alive, Close"))
    651   {
    652     fprintf (stderr,
    653              "Cannot add \"Connection\" header with \"keep-Alive, Close\".\n");
    654     MHD_destroy_response (r);
    655     return 4;
    656   }
    657   if (! expect_str (MHD_get_response_header (r, "Connection"), "close"))
    658   {
    659     MHD_destroy_response (r);
    660     return 4;
    661   }
    662   if (MHD_YES != MHD_add_response_header (r, "Connection",
    663                                           "close, additional-token"))
    664   {
    665     fprintf (stderr, "Cannot add \"Connection\" header with "
    666              "\"close, additional-token\".\n");
    667     MHD_destroy_response (r);
    668     return 4;
    669   }
    670   if (! expect_str (MHD_get_response_header (r, "Connection"),
    671                     "close, additional-token"))
    672   {
    673     MHD_destroy_response (r);
    674     return 4;
    675   }
    676   if (MHD_NO != MHD_add_response_header (r, "Connection", "keep-Alive"))
    677   {
    678     fprintf (stderr,
    679              "Successfully added \"Connection\" header with \"keep-Alive\".\n");
    680     MHD_destroy_response (r);
    681     return 4;
    682   }
    683   if (! expect_str (MHD_get_response_header (r, "Connection"),
    684                     "close, additional-token"))
    685   {
    686     MHD_destroy_response (r);
    687     return 4;
    688   }
    689   if (MHD_YES != MHD_del_response_header (r, "Connection",
    690                                           "additional-token,close"))
    691   {
    692     fprintf (stderr, "Cannot remove tokens from \"Connection\".\n");
    693     MHD_destroy_response (r);
    694     return 4;
    695   }
    696   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    697   {
    698     MHD_destroy_response (r);
    699     return 4;
    700   }
    701 
    702   if (MHD_YES != MHD_add_response_header (r, "Connection",
    703                                           "Keep-aLive, token-1"))
    704   {
    705     fprintf (stderr,
    706              "Cannot add \"Connection\" header with \"Keep-aLive, token-1\".\n")
    707     ;
    708     MHD_destroy_response (r);
    709     return 4;
    710   }
    711   if (! expect_str (MHD_get_response_header (r, "Connection"), "token-1"))
    712   {
    713     MHD_destroy_response (r);
    714     return 4;
    715   }
    716   if (MHD_YES != MHD_add_response_header (r, "Connection",
    717                                           "Keep-aLive, token-2"))
    718   {
    719     fprintf (stderr,
    720              "Cannot add \"Connection\" header with \"Keep-aLive, token-2\".\n")
    721     ;
    722     MHD_destroy_response (r);
    723     return 4;
    724   }
    725   if (! expect_str (MHD_get_response_header (r, "Connection"),
    726                     "token-1, token-2"))
    727   {
    728     MHD_destroy_response (r);
    729     return 4;
    730   }
    731   if (MHD_YES != MHD_add_response_header (r, "Connection",
    732                                           "Keep-aLive, token-3, close"))
    733   {
    734     fprintf (stderr,
    735              "Cannot add \"Connection\" header with \"Keep-aLive, token-3, close\".\n");
    736     MHD_destroy_response (r);
    737     return 4;
    738   }
    739   if (! expect_str (MHD_get_response_header (r, "Connection"),
    740                     "close, token-1, token-2, token-3"))
    741   {
    742     MHD_destroy_response (r);
    743     return 4;
    744   }
    745   if (MHD_YES != MHD_del_response_header (r, "Connection",
    746                                           "close"))
    747   {
    748     fprintf (stderr, "Cannot remove \"close\" tokens from \"Connection\".\n");
    749     MHD_destroy_response (r);
    750     return 4;
    751   }
    752   if (! expect_str (MHD_get_response_header (r, "Connection"),
    753                     "token-1, token-2, token-3"))
    754   {
    755     MHD_destroy_response (r);
    756     return 4;
    757   }
    758   if (MHD_YES != MHD_add_response_header (r, "Connection", "Keep-aLive, close"))
    759   {
    760     fprintf (stderr,
    761              "Cannot add \"Connection\" header with \"Keep-aLive, token-3, close\".\n");
    762     MHD_destroy_response (r);
    763     return 4;
    764   }
    765   if (! expect_str (MHD_get_response_header (r, "Connection"),
    766                     "close, token-1, token-2, token-3"))
    767   {
    768     MHD_destroy_response (r);
    769     return 4;
    770   }
    771   if (MHD_YES != MHD_del_response_header (r, "Connection",
    772                                           "close, token-1, Keep-Alive, token-2, token-3"))
    773   {
    774     fprintf (stderr, "Cannot remove \"close\" tokens from \"Connection\".\n");
    775     MHD_destroy_response (r);
    776     return 4;
    777   }
    778   if (! expect_str (MHD_get_response_header (r, "Connection"), NULL))
    779   {
    780     MHD_destroy_response (r);
    781     return 4;
    782   }
    783 
    784   if (MHD_YES != MHD_add_response_header (r, "Date",
    785                                           "Wed, 01 Apr 2015 00:00:00 GMT"))
    786   {
    787     fprintf (stderr,
    788              "Cannot add \"Date\" header with \"Wed, 01 Apr 2015 00:00:00 GMT\".\n");
    789     MHD_destroy_response (r);
    790     return 5;
    791   }
    792   if (! expect_str (MHD_get_response_header (r, "Date"),
    793                     "Wed, 01 Apr 2015 00:00:00 GMT"))
    794   {
    795     MHD_destroy_response (r);
    796     return 5;
    797   }
    798   if (MHD_YES != MHD_add_response_header (r, "Date",
    799                                           "Thu, 01 Apr 2021 00:00:00 GMT"))
    800   {
    801     fprintf (stderr,
    802              "Cannot add \"Date\" header with \"Thu, 01 Apr 2021 00:00:00 GMT\".\n");
    803     MHD_destroy_response (r);
    804     return 5;
    805   }
    806   if (! expect_str (MHD_get_response_header (r, "Date"),
    807                     "Thu, 01 Apr 2021 00:00:00 GMT"))
    808   {
    809     MHD_destroy_response (r);
    810     return 5;
    811   }
    812   if (MHD_YES != MHD_del_response_header (r, "Date",
    813                                           "Thu, 01 Apr 2021 00:00:00 GMT"))
    814   {
    815     fprintf (stderr, "Cannot remove \"Date\" header.\n");
    816     MHD_destroy_response (r);
    817     return 5;
    818   }
    819   if (! expect_str (MHD_get_response_header (r, "Date"), NULL))
    820   {
    821     MHD_destroy_response (r);
    822     return 5;
    823   }
    824 
    825   if (MHD_YES != MHD_add_response_header (r, MHD_HTTP_HEADER_TRANSFER_ENCODING,
    826                                           "chunked"))
    827   {
    828     fprintf (stderr,
    829              "Cannot add \"" MHD_HTTP_HEADER_TRANSFER_ENCODING \
    830              "\" header with \"chunked\".\n");
    831     MHD_destroy_response (r);
    832     return 6;
    833   }
    834   if (! expect_str (MHD_get_response_header (r,
    835                                              MHD_HTTP_HEADER_TRANSFER_ENCODING),
    836                     "chunked"))
    837   {
    838     MHD_destroy_response (r);
    839     return 6;
    840   }
    841   if (MHD_YES != MHD_add_response_header (r, MHD_HTTP_HEADER_TRANSFER_ENCODING,
    842                                           "chunked"))
    843   {
    844     fprintf (stderr,
    845              "Cannot add \"" MHD_HTTP_HEADER_TRANSFER_ENCODING \
    846              "\" second header with \"chunked\".\n");
    847     MHD_destroy_response (r);
    848     return 6;
    849   }
    850   if (! expect_str (MHD_get_response_header (r,
    851                                              MHD_HTTP_HEADER_TRANSFER_ENCODING),
    852                     "chunked"))
    853   {
    854     MHD_destroy_response (r);
    855     return 6;
    856   }
    857   if (MHD_NO != MHD_add_response_header (r, MHD_HTTP_HEADER_TRANSFER_ENCODING,
    858                                          "identity"))
    859   {
    860     fprintf (stderr,
    861              "Successfully added \"" MHD_HTTP_HEADER_TRANSFER_ENCODING \
    862              "\" header with \"identity\".\n");
    863     MHD_destroy_response (r);
    864     return 6;
    865   }
    866   if (! expect_str (MHD_get_response_header (r,
    867                                              MHD_HTTP_HEADER_TRANSFER_ENCODING),
    868                     "chunked"))
    869   {
    870     MHD_destroy_response (r);
    871     return 6;
    872   }
    873   if (MHD_YES != MHD_del_response_header (r, MHD_HTTP_HEADER_TRANSFER_ENCODING,
    874                                           "chunked"))
    875   {
    876     fprintf (stderr, "Cannot remove \"" MHD_HTTP_HEADER_TRANSFER_ENCODING \
    877              "\" header.\n");
    878     MHD_destroy_response (r);
    879     return 6;
    880   }
    881   if (! expect_str (MHD_get_response_header (r,
    882                                              MHD_HTTP_HEADER_TRANSFER_ENCODING),
    883                     NULL))
    884   {
    885     MHD_destroy_response (r);
    886     return 6;
    887   }
    888 
    889   MHD_destroy_response (r);
    890   printf ("All tests has been successfully passed.\n");
    891   return 0;
    892 }