Git init
[external/curl.git] / tests / libtest / lib514.c
1 /*****************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  */
9
10 #include "test.h"
11
12 #include "memdebug.h"
13
14 int test(char *URL)
15 {
16   CURL *curl;
17   CURLcode res=CURLE_OK;
18
19   if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
20     fprintf(stderr, "curl_global_init() failed\n");
21     return TEST_ERR_MAJOR_BAD;
22   }
23
24   if ((curl = curl_easy_init()) == NULL) {
25     fprintf(stderr, "curl_easy_init() failed\n");
26     curl_global_cleanup();
27     return TEST_ERR_MAJOR_BAD;
28   }
29
30   /* First set the URL that is about to receive our POST. */
31   test_setopt(curl, CURLOPT_URL, URL);
32
33   /* Based on a bug report by Niels van Tongeren on June 29, 2004:
34
35   A weird situation occurs when request 1 is a POST request and the request
36   2 is a HEAD request. For the POST request we set the CURLOPT_POSTFIELDS,
37   CURLOPT_POSTFIELDSIZE and CURLOPT_POST options. For the HEAD request we
38   set the CURLOPT_NOBODY option to '1'.
39
40   */
41
42   test_setopt(curl, CURLOPT_POSTFIELDS, "moo");
43   test_setopt(curl, CURLOPT_POSTFIELDSIZE, 3L);
44   test_setopt(curl, CURLOPT_POST, 1L);
45
46   /* this is where transfer 1 would take place, but skip that and change
47      options right away instead */
48
49   test_setopt(curl, CURLOPT_NOBODY, 1L);
50
51   test_setopt(curl, CURLOPT_VERBOSE, 1L); /* show verbose for debug */
52   test_setopt(curl, CURLOPT_HEADER, 1L); /* include header */
53
54   /* Now, we should be making a fine HEAD request */
55
56   /* Perform the request 2, res will get the return code */
57   res = curl_easy_perform(curl);
58
59 test_cleanup:
60
61   /* always cleanup */
62   curl_easy_cleanup(curl);
63   curl_global_cleanup();
64
65   return (int)res;
66 }