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

« back to all changes in this revision

Viewing changes to tests/libtest/lib510.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: lib510.c,v 1.5 2006-10-25 09:20:44 yangtse Exp $
 
9
 */
 
10
 
1
11
#include "test.h"
2
12
 
3
13
static const char *post[]={
41
51
  struct WriteThis pooh;
42
52
  pooh.counter = 0;
43
53
 
 
54
  if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
 
55
    fprintf(stderr, "curl_global_init() failed\n");
 
56
    return TEST_ERR_MAJOR_BAD;
 
57
  }
 
58
 
 
59
  if ((curl = curl_easy_init()) == NULL) {
 
60
    fprintf(stderr, "curl_easy_init() failed\n");
 
61
    curl_global_cleanup();
 
62
    return TEST_ERR_MAJOR_BAD;
 
63
  }
 
64
 
44
65
  slist = curl_slist_append(slist, "Transfer-Encoding: chunked");
45
 
 
46
 
  curl = curl_easy_init();
47
 
  if(curl) {
48
 
    /* First set the URL that is about to receive our POST. */
49
 
    curl_easy_setopt(curl, CURLOPT_URL, URL);
50
 
 
51
 
    /* Now specify we want to POST data */
52
 
    curl_easy_setopt(curl, CURLOPT_POST, TRUE);
53
 
 
54
 
    /* we want to use our own read function */
55
 
    curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
56
 
 
57
 
    /* pointer to pass to our read function */
58
 
    curl_easy_setopt(curl, CURLOPT_INFILE, &pooh);
59
 
 
60
 
    /* get verbose debug output please */
61
 
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
62
 
 
63
 
    /* include headers in the output */
64
 
    curl_easy_setopt(curl, CURLOPT_HEADER, TRUE);
65
 
 
66
 
    /* enforce chunked transfer by setting the header */
67
 
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
68
 
 
69
 
    /* Perform the request, res will get the return code */
70
 
    res = curl_easy_perform(curl);
71
 
 
72
 
    /* always cleanup */
 
66
  if (slist == NULL) {
 
67
    fprintf(stderr, "curl_slist_append() failed\n");
73
68
    curl_easy_cleanup(curl);
74
 
 
 
69
    curl_global_cleanup();
 
70
    return TEST_ERR_MAJOR_BAD;
75
71
  }
76
72
 
 
73
  /* First set the URL that is about to receive our POST. */
 
74
  curl_easy_setopt(curl, CURLOPT_URL, URL);
 
75
 
 
76
  /* Now specify we want to POST data */
 
77
  curl_easy_setopt(curl, CURLOPT_POST, TRUE);
 
78
 
 
79
  /* we want to use our own read function */
 
80
  curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
 
81
 
 
82
  /* pointer to pass to our read function */
 
83
  curl_easy_setopt(curl, CURLOPT_INFILE, &pooh);
 
84
 
 
85
  /* get verbose debug output please */
 
86
  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
 
87
 
 
88
  /* include headers in the output */
 
89
  curl_easy_setopt(curl, CURLOPT_HEADER, TRUE);
 
90
 
 
91
  /* enforce chunked transfer by setting the header */
 
92
  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
 
93
 
 
94
  /* Perform the request, res will get the return code */
 
95
  res = curl_easy_perform(curl);
 
96
 
 
97
  /* clean up the headers list */
77
98
  if(slist)
78
 
    /* clean up the headers list */
79
99
    curl_slist_free_all(slist);
80
100
 
 
101
  /* always cleanup */
 
102
  curl_easy_cleanup(curl);
 
103
  curl_global_cleanup();
 
104
 
81
105
  return res;
82
106
}