|
| 1 | +/* |
| 2 | + * Copyright (c) Kristaps Dzonsons <[email protected]> |
| 3 | + * |
| 4 | + * Permission to use, copy, modify, and distribute this software for any |
| 5 | + * purpose with or without fee is hereby granted, provided that the above |
| 6 | + * copyright notice and this permission notice appear in all copies. |
| 7 | + * |
| 8 | + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | + */ |
| 16 | +#include "../config.h" |
| 17 | + |
| 18 | +#include <stdarg.h> |
| 19 | +#include <stdint.h> |
| 20 | +#include <stdlib.h> |
| 21 | +#include <string.h> |
| 22 | +#include <unistd.h> |
| 23 | + |
| 24 | +#include <curl/curl.h> |
| 25 | + |
| 26 | +#include "../kcgi.h" |
| 27 | +#include "regress.h" |
| 28 | + |
| 29 | +static int |
| 30 | +parent(CURL *curl) |
| 31 | +{ |
| 32 | + struct curl_slist *slist = NULL; |
| 33 | + int ret; |
| 34 | + |
| 35 | + slist = curl_slist_append(slist, "Testing:123"); |
| 36 | + slist = curl_slist_append(slist, "Testing-Test:321"); |
| 37 | + curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:17123/"); |
| 38 | + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist); |
| 39 | + ret = curl_easy_perform(curl); |
| 40 | + curl_slist_free_all(slist); |
| 41 | + return ret == CURLE_OK; |
| 42 | +} |
| 43 | + |
| 44 | +static int |
| 45 | +child(void) |
| 46 | +{ |
| 47 | + struct kreq r; |
| 48 | + const char *page = "index"; |
| 49 | + size_t i, found1 = 0, found2 = 0; |
| 50 | + |
| 51 | + if (khttp_parse(&r, NULL, 0, &page, 1, 0) != KCGI_OK) |
| 52 | + return 0; |
| 53 | + |
| 54 | + for (i = 0; i < r.envsz; i++) { |
| 55 | + if (strcmp(r.envs[i].key, "HTTP_TESTING") == 0) |
| 56 | + found1 += strcmp(r.envs[i].val, "123") == 0; |
| 57 | + else if (strcmp(r.envs[i].key, "HTTP_TESTING_TEST") == 0) |
| 58 | + found2 += strcmp(r.envs[i].val, "321") == 0; |
| 59 | + } |
| 60 | + |
| 61 | + if (found1 != 1 || found2 != 1 ) |
| 62 | + return 0; |
| 63 | + |
| 64 | + khttp_head(&r, kresps[KRESP_STATUS], |
| 65 | + "%s", khttps[KHTTP_200]); |
| 66 | + khttp_head(&r, kresps[KRESP_CONTENT_TYPE], |
| 67 | + "%s", kmimetypes[KMIME_TEXT_HTML]); |
| 68 | + khttp_body(&r); |
| 69 | + khttp_free(&r); |
| 70 | + return 1; |
| 71 | +} |
| 72 | + |
| 73 | +int |
| 74 | +main(int argc, char *argv[]) |
| 75 | +{ |
| 76 | + |
| 77 | + return regress_cgi(parent, child) ? EXIT_SUCCESS : EXIT_FAILURE; |
| 78 | +} |
0 commit comments