]> granicus.if.org Git - curl/commitdiff
lost of more into on how to tweak some headers
authorDaniel Stenberg <daniel@haxx.se>
Mon, 23 Aug 2004 14:22:44 +0000 (14:22 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 23 Aug 2004 14:22:44 +0000 (14:22 +0000)
docs/examples/post-callback.c

index 76d1e1ba55e6d8d7c5bfc7c05e7ba262f4741088..ecffce3033c26e2245c844d09ec41ccf7564a2b8 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
- *                                  _   _ ____  _     
- *  Project                     ___| | | |  _ \| |    
- *                             / __| | | | |_) | |    
- *                            | (__| |_| |  _ <| |___ 
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
  * $Id$
@@ -57,9 +57,6 @@ int main(void)
     /* Now specify we want to POST data */
     curl_easy_setopt(curl, CURLOPT_POST, TRUE);
 
-    /* Set the expected POST size */
-    curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, pooh.sizeleft);
-
     /* we want to use our own read function */
     curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
 
@@ -69,6 +66,47 @@ int main(void)
     /* get verbose debug output please */
     curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
 
+    /*
+      If you use POST to a HTTP 1.1 server, you can send data without knowing
+      the size before starting the POST if you use chunked encoding. You
+      enable this by adding a header like "Transfer-Encoding: chunked" with
+      CURLOPT_HTTPHEADER. With HTTP 1.0 or without chunked transfer, you must
+      specify the size in the request.
+    */
+#ifdef USE_CHUNKED
+    {
+      curl_slist *chunk = NULL;
+
+      chunk = curl_slist_append(chunk, "Transfer-Encoding: chunked");
+      res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER);
+      /* use curl_slist_free_all() after the *perform() call to free this
+         list again */
+    }
+#else
+    /* Set the expected POST size. If you want to POST large amounts of data,
+       consider CURLOPT_POSTFIELDSIZE_LARGE */
+    curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, pooh.sizeleft);
+#endif
+
+#ifdef DISABLE_EXPECT
+    /*
+      Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue"
+      header.  You can disable this header with CURLOPT_HTTPHEADER as usual.
+      NOTE: if you want chunked transfer too, you need to combine these two
+      since you can only set one list of headers with CURLOPT_HTTPHEADER. */
+
+    /* A less good option would be to enforce HTTP 1.0, but that might also
+       have other implications. */
+    {
+      curl_slist *chunk = NULL;
+
+      chunk = curl_slist_append(chunk, "Expect:");
+      res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER);
+      /* use curl_slist_free_all() after the *perform() call to free this
+         list again */
+    }
+#endif
+
     /* Perform the request, res will get the return code */
     res = curl_easy_perform(curl);