ksgi

Форк
0
/
test-gzip.c 
98 строк · 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
#if HAVE_ZLIB
31

32
struct	buf {
33
	char	  buf[BUFSIZ];
34
	size_t	  sz;
35
};
36

37
static int
38
parentwrite(void *ptr, size_t sz, size_t nm, void *dat)
39
{
40
	struct buf	*buf = dat;
41

42
	if (buf->sz + (sz * nm) + 1 > BUFSIZ)
43
		return(-1);
44
	memcpy(buf->buf + buf->sz, ptr, sz * nm);
45
	buf->sz += sz * nm;
46
	buf->buf[buf->sz] = '\0';
47
	return(sz * nm);
48
}
49

50
static int
51
parent(CURL *curl)
52
{
53
	struct buf	 buf;
54

55
	memset(&buf, 0, sizeof(struct buf));
56
	curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, parentwrite);
57
	curl_easy_setopt(curl, CURLOPT_HEADERDATA, &buf);
58
	curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:17123/");
59
	curl_easy_setopt(curl, CURLOPT_ENCODING, "gzip");
60
	if (CURLE_OK != curl_easy_perform(curl))
61
		return(0);
62
	return(NULL != strstr(buf.buf, "Content-Encoding: gzip"));
63
}
64

65
static int
66
child(void)
67
{
68
	struct kreq	 r;
69
	const char 	*page = "index";
70

71
	if (KCGI_OK != khttp_parse(&r, NULL, 0, &page, 1, 0))
72
		return(0);
73

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

84
int
85
main(int argc, char *argv[])
86
{
87

88
	return(regress_cgi(parent, child) ? EXIT_SUCCESS : EXIT_FAILURE);
89
}
90

91
#else
92
int
93
main(int argc, char *argv[])
94
{
95

96
	return(EXIT_SUCCESS);
97
}
98
#endif
99

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

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

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

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