ksgi

Форк
0
/
test-header-bad.c 
86 строк · 2.3 Кб
1
/*	$Id$ */
2
/*
3
 * Copyright (c) 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4
 *
5
 * Permission to use, copy, modify, and distribute this software for any
6
 * purpose with or without fee is hereby granted, provided that the above
7
 * copyright notice and this permission notice appear in all copies.
8
 *
9
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
 */
17
#include "../config.h"
18

19
#include <stdarg.h>
20
#include <stdint.h>
21
#include <stdlib.h>
22
#include <string.h>
23
#include <unistd.h>
24

25
#include <curl/curl.h>
26

27
#include "../kcgi.h"
28
#include "regress.h"
29

30
static int
31
parent(CURL *curl)
32
{
33
	struct curl_slist *slist;
34
	int		   ret;
35

36
	slist = NULL;
37
	slist = curl_slist_append(slist, "Testing\tfoo:123");
38
	slist = curl_slist_append(slist, "Testing-Test:321");
39
	slist = curl_slist_append(slist, "Test\bing-Test:321");
40
	curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:17123/");
41
	curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
42
	ret = curl_easy_perform(curl);
43
	curl_slist_free_all(slist);
44
	return(CURLE_OK == ret);
45
}
46

47
static int
48
child(void)
49
{
50
	struct kreq	 r;
51
	const char 	*page = "index";
52
	size_t		 i, found1, found2;
53

54
	if (KCGI_OK != khttp_parse(&r, NULL, 0, &page, 1, 0))
55
		return(0);
56

57
	found1 = found2 = 0;
58
	for (i = 0; i < r.reqsz; i++) {
59
		if (0 == strcmp(r.reqs[i].key, "Testing\tfoo")) 
60
			found1++;
61
		else if (0 == strcmp(r.reqs[i].key, "Test\bing-Test")) 
62
			found1++;
63
		else if (0 == strcmp(r.reqs[i].key, ""))
64
			found1++;
65
		else if (0 == strcmp(r.reqs[i].key, "Testing-Test")) 
66
			found2 += 0 == strcmp(r.reqs[i].val, "321");
67
	}
68

69
	if (found1 || 1 != found2) 
70
		return(0);
71

72
	khttp_head(&r, kresps[KRESP_STATUS], 
73
		"%s", khttps[KHTTP_200]);
74
	khttp_head(&r, kresps[KRESP_CONTENT_TYPE], 
75
		"%s", kmimetypes[KMIME_TEXT_HTML]);
76
	khttp_body(&r);
77
	khttp_free(&r);
78
	return(1);
79
}
80

81
int
82
main(int argc, char *argv[])
83
{
84

85
	return(regress_cgi(parent, child) ? EXIT_SUCCESS : EXIT_FAILURE);
86
}
87

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.