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