~ubuntu-branches/ubuntu/lucid/curl/lucid-201101212007

« back to all changes in this revision

Viewing changes to tests/libtest/lib514.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-05-16 15:16:54 UTC
  • mto: (3.1.1 lenny) (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: james.westby@ubuntu.com-20070516151654-x9nkigtr2j0i8d0v
Tags: upstream-7.16.2
ImportĀ upstreamĀ versionĀ 7.16.2

Show diffs side-by-side

added added

removed removed

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