1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ***************************************************************************/
22#include "test.h"
23
24#include "testutil.h"
25#include "warnless.h"
26#include "memdebug.h"
27
28size_t WriteOutput(void *ptr, size_t size, size_t nmemb, void *stream);
29size_t WriteHeader(void *ptr, size_t size, size_t nmemb, void *stream);
30
31static unsigned long realHeaderSize = 0;
32
33int test(char *URL)
34{
35 long headerSize;
36 CURLcode code;
37 CURL *curl = NULL;
38 int res = 0;
39
40 global_init(CURL_GLOBAL_ALL);
41
42 easy_init(curl);
43
44 easy_setopt(curl, CURLOPT_PROXY, libtest_arg2); /* set in first.c */
45
46 easy_setopt(curl, CURLOPT_WRITEFUNCTION, *WriteOutput);
47 easy_setopt(curl, CURLOPT_HEADERFUNCTION, *WriteHeader);
48
49 easy_setopt(curl, CURLOPT_HEADER, 1L);
50 easy_setopt(curl, CURLOPT_VERBOSE, 1L);
51 easy_setopt(curl, CURLOPT_URL, URL);
52 easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
53
54 code = curl_easy_perform(curl);
55 if(CURLE_OK != code) {
56 fprintf(stderr, "%s:%d curl_easy_perform() failed, "
57 "with code %d (%s)\n",
58 __FILE__, __LINE__, (int)code, curl_easy_strerror(code));
59 res = TEST_ERR_MAJOR_BAD;
60 goto test_cleanup;
61 }
62
63 code = curl_easy_getinfo(curl, CURLINFO_HEADER_SIZE, &headerSize);
64 if(CURLE_OK != code) {
65 fprintf(stderr, "%s:%d curl_easy_getinfo() failed, "
66 "with code %d (%s)\n",
67 __FILE__, __LINE__, (int)code, curl_easy_strerror(code));
68 res = TEST_ERR_MAJOR_BAD;
69 goto test_cleanup;
70 }
71
72 printf("header length is ........: %ld\n", headerSize);
73 printf("header length should be..: %lu\n", realHeaderSize);
74
75test_cleanup:
76
77 curl_easy_cleanup(curl);
78 curl_global_cleanup();
79
80 return res;
81}
82
83size_t WriteOutput(void *ptr, size_t size, size_t nmemb, void *stream)
84{
85 fwrite(ptr, size, nmemb, stream);
86 return nmemb * size;
87}
88
89size_t WriteHeader(void *ptr, size_t size, size_t nmemb, void *stream)
90{
91 (void)ptr;
92 (void)stream;
93
94 realHeaderSize += curlx_uztoul(size * nmemb);
95
96 return nmemb * size;
97}
98