tizen 2.3.1 release
[external/curl.git] / tests / libtest / lib1526.c
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2014, Vijay Panghal, <vpanghal@maginatics.com>, 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 http://curl.haxx.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
23 /*
24  * This unit test PUT http data over proxy. Proxy header will be different
25  * from server http header
26  */
27
28 #include "test.h"
29
30 #include "memdebug.h"
31
32 static char data [] = "Hello Cloud!\n";
33
34 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
35 {
36   size_t  amount = nmemb * size; /* Total bytes curl wants */
37   if (amount < strlen(data)) {
38     return strlen(data);
39   }
40   (void)stream;
41   memcpy(ptr, data, strlen(data));
42   return strlen(data);
43 }
44
45 int test(char *URL)
46 {
47   CURL *curl = NULL;
48   CURLcode res = CURLE_FAILED_INIT;
49   /* http and proxy header list*/
50   struct curl_slist *hhl = NULL, *phl = NULL, *tmp = NULL;
51
52   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
53     fprintf(stderr, "curl_global_init() failed\n");
54     return TEST_ERR_MAJOR_BAD;
55   }
56
57   if((curl = curl_easy_init()) == NULL) {
58     fprintf(stderr, "curl_easy_init() failed\n");
59     curl_global_cleanup();
60     return TEST_ERR_MAJOR_BAD;
61   }
62
63   hhl = curl_slist_append(hhl, "User-Agent: Http Agent");
64   phl = curl_slist_append(phl, "User-Agent: Proxy Agent");
65   if (!hhl || !phl) {
66     goto test_cleanup;
67   }
68   tmp = curl_slist_append(phl, "Expect:");
69   if (!tmp) {
70     goto test_cleanup;
71   }
72   phl = tmp;
73
74   test_setopt(curl, CURLOPT_URL, URL);
75   test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
76   test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
77   test_setopt(curl, CURLOPT_PROXYHEADER, phl);
78   test_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_SEPARATE);
79   test_setopt(curl, CURLOPT_POST, 0L);
80   test_setopt(curl, CURLOPT_UPLOAD, 1L);
81   test_setopt(curl, CURLOPT_VERBOSE, 1L);
82   test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
83   test_setopt(curl, CURLOPT_HEADER, 1L);
84   test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
85   test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
86   test_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
87   test_setopt(curl, CURLOPT_INFILESIZE, strlen(data));
88
89   res = curl_easy_perform(curl);
90
91 test_cleanup:
92
93   curl_easy_cleanup(curl);
94
95   curl_slist_free_all(hhl);
96
97   curl_slist_free_all(phl);
98
99   curl_global_cleanup();
100
101   return (int)res;
102 }
103