]> granicus.if.org Git - curl/commitdiff
opts: examples added to 8 more libcurl option man pages
authorDaniel Stenberg <daniel@haxx.se>
Sat, 6 May 2017 21:38:39 +0000 (23:38 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Sat, 6 May 2017 21:38:39 +0000 (23:38 +0200)
docs/libcurl/opts/CURLINFO_CONTENT_LENGTH_UPLOAD.3
docs/libcurl/opts/CURLINFO_CONTENT_TYPE.3
docs/libcurl/opts/CURLINFO_COOKIELIST.3
docs/libcurl/opts/CURLINFO_FTP_ENTRY_PATH.3
docs/libcurl/opts/CURLINFO_HEADER_SIZE.3
docs/libcurl/opts/CURLINFO_HTTPAUTH_AVAIL.3
docs/libcurl/opts/CURLINFO_HTTP_CONNECTCODE.3
docs/libcurl/opts/CURLINFO_NUM_CONNECTS.3

index e40d5ea9e16bc0eb36e2bdf481410a688f542143..39adfe797d3f36c3d780f6910f314e8d78efc7a9 100644 (file)
@@ -5,7 +5,7 @@
 .\" *                            | (__| |_| |  _ <| |___
 .\" *                             \___|\___/|_| \_\_____|
 .\" *
-.\" * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
 .\" *
 .\" * This software is licensed as described in the file COPYING, which
 .\" * you should have received as part of this distribution. The terms
@@ -34,7 +34,24 @@ Pass a pointer to a double to receive the specified size of the upload.  Since
 .SH PROTOCOLS
 All
 .SH EXAMPLE
-TODO
+.nf
+CURL *curl = curl_easy_init();
+if(curl) {
+  curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
+
+  /* Perform the upload */
+  res = curl_easy_perform(curl);
+
+  if(!res) {
+    /* check the size */
+    double cl;
+    res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &cl);
+    if(!res) {
+      printf("Size: %.0f\n", cl);
+    }
+  }
+}
+.fi
 .SH AVAILABILITY
 Added in 7.6.1
 .SH RETURN VALUE
index 7536000c4a15576b9dcea822ccd26e87fe42ca7f..a7cd70fe907708baef6c27c7de6b9f47ba018573 100644 (file)
@@ -5,7 +5,7 @@
 .\" *                            | (__| |_| |  _ <| |___
 .\" *                             \___|\___/|_| \_\_____|
 .\" *
-.\" * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
 .\" *
 .\" * This software is licensed as described in the file COPYING, which
 .\" * you should have received as part of this distribution. The terms
@@ -39,7 +39,24 @@ corresponding CURL handle.
 .SH PROTOCOLS
 HTTP(S)
 .SH EXAMPLE
-TODO
+.nf
+CURL *curl = curl_easy_init();
+if(curl) {
+  curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
+
+  res = curl_easy_perform(curl);
+
+  if(!res) {
+    /* extract the content-type */
+    char *ct = NULL;
+    res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);
+    if(!res && ct) {
+      printf("Content-Type: %s\n", ct);
+    }
+  }
+  curl_easy_cleanup(curl);
+}
+.fi
 .SH AVAILABILITY
 Added in 7.9.4
 .SH RETURN VALUE
index b9f75f4db5dba883b896d5b755acfb08814a3ee5..18203dba771ed5ff1133d15f08e8eeb3022a0817 100644 (file)
@@ -5,7 +5,7 @@
 .\" *                            | (__| |_| |  _ <| |___
 .\" *                             \___|\___/|_| \_\_____|
 .\" *
-.\" * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
 .\" *
 .\" * This software is licensed as described in the file COPYING, which
 .\" * you should have received as part of this distribution. The terms
@@ -40,7 +40,33 @@ domain name are not exported by this option.
 .SH PROTOCOLS
 HTTP(S)
 .SH EXAMPLE
-TODO
+.nf
+CURL *curl = curl_easy_init();
+if(curl) {
+  curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
+
+  /* enable the cookie engine with a non-existing file */
+  curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "-");
+
+  res = curl_easy_perform(curl);
+
+  if(!res) {
+    /* extract all known cookies */
+    struct curl_slist *cookies = NULL;
+    res = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies);
+    if(!res && cookies) {
+      /* a linked list of cookies in cookie file format */
+      while(cookies) {
+        printf("%s", cookies->data);
+        cookies = cookies->next;
+      }
+      /* we must free these cookies when we're done */
+      curl_slist_free_all(cookies);
+    }
+  }
+  curl_easy_cleanup(curl);
+}
+.fi
 .SH AVAILABILITY
 Added in 7.14.1
 .SH RETURN VALUE
index e7d7fcff24ab0ea34f5c9a509dcc684851db66f2..716ff9feeb808966336bc051cc97c60419d1ada9 100644 (file)
@@ -5,7 +5,7 @@
 .\" *                            | (__| |_| |  _ <| |___
 .\" *                             \___|\___/|_| \_\_____|
 .\" *
-.\" * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
 .\" *
 .\" * This software is licensed as described in the file COPYING, which
 .\" * you should have received as part of this distribution. The terms
@@ -39,7 +39,24 @@ corresponding CURL handle.
 .SH PROTOCOLS
 FTP(S) and SFTP
 .SH EXAMPLE
-TODO
+.nf
+CURL *curl = curl_easy_init();
+if(curl) {
+  curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com");
+
+  res = curl_easy_perform(curl);
+
+  if(!res) {
+    /* extract the entry path */
+    char *ep = NULL;
+    res = curl_easy_getinfo(curl, CURLINFO_FTP_ENTRY_PATH, &ep);
+    if(!res && ep) {
+      printf("Entry path was: %s\n", ep);
+    }
+  }
+  curl_easy_cleanup(curl);
+}
+.fi
 .SH AVAILABILITY
 Added in 7.15.4. Works for SFTP since 7.21.4
 .SH RETURN VALUE
index b687c80b96dbefba8a7ce565abc3f7dce2f2b390..f7d9e7e54f00ea6c925e0fcd0fc334fc1038c357 100644 (file)
@@ -5,7 +5,7 @@
 .\" *                            | (__| |_| |  _ <| |___
 .\" *                             \___|\___/|_| \_\_____|
 .\" *
-.\" * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
 .\" *
 .\" * This software is licensed as described in the file COPYING, which
 .\" * you should have received as part of this distribution. The terms
@@ -36,7 +36,21 @@ The total includes the size of any received headers suppressed by
 .SH PROTOCOLS
 All
 .SH EXAMPLE
-TODO
+.nf
+CURL *curl = curl_easy_init();
+if(curl) {
+  CURLcode res;
+  curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
+  res = curl_easy_perform(curl);
+  if(res == CURLE_OK) {
+    long size;
+    res = curl_easy_getinfo(curl, CURLINFO_HEADER_SIZE, &size);
+    if(!res)
+      printf("Header size: %ld bytes\n", size);
+  }
+  curl_easy_cleanup(curl);
+}
+.fi
 .SH AVAILABILITY
 Added in 7.4.1
 .SH RETURN VALUE
index a5d0e725ace11a518a43f187123c1d2d8deea5dc..da6ee77faff6ded21afcd282ab617fc0cd8d9370 100644 (file)
@@ -5,7 +5,7 @@
 .\" *                            | (__| |_| |  _ <| |___
 .\" *                             \___|\___/|_| \_\_____|
 .\" *
-.\" * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
 .\" *
 .\" * This software is licensed as described in the file COPYING, which
 .\" * you should have received as part of this distribution. The terms
@@ -35,7 +35,32 @@ bits is explained in the \fICURLOPT_HTTPAUTH(3)\fP option for
 .SH PROTOCOLS
 HTTP(S)
 .SH EXAMPLE
-TODO
+.nf
+CURL *curl = curl_easy_init();
+if(curl) {
+  curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
+
+  res = curl_easy_perform(curl);
+
+  if(!res) {
+    /* extract the content-type */
+    long auth;
+    res = curl_easy_getinfo(curl, CURLINFO_HTTPAUTH_AVAIL, &auth);
+    if(!res) {
+      if(!auth)
+        printf("No auth available, perhaps no 401?\n");
+      else {
+        printf("%s%s%s%s\n",
+               auth & CURLAUTH_BASIC ? "Basic ":"",
+               auth & CURLAUTH_DIGEST ? "Digest ":"",
+               auth & CURLAUTH_NEGOTIATE ? "Negotiate ":"",
+               auth % CURLAUTH_NTLM ? "NTLM ":"");
+      }
+    }
+  }
+  curl_easy_cleanup(curl);
+}
+.fi
 .SH AVAILABILITY
 Added in 7.10.8
 .SH RETURN VALUE
index acfef77fe3acf2e708bd8d27fb5951632b116293..4ecbcaaa7bc27e1705155c33b32e68f211563d91 100644 (file)
@@ -5,7 +5,7 @@
 .\" *                            | (__| |_| |  _ <| |___
 .\" *                             \___|\___/|_| \_\_____|
 .\" *
-.\" * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
 .\" *
 .\" * This software is licensed as described in the file COPYING, which
 .\" * you should have received as part of this distribution. The terms
@@ -34,7 +34,24 @@ was available.
 .SH PROTOCOLS
 HTTP
 .SH EXAMPLE
-TODO
+.nf
+CURL *curl = curl_easy_init();
+if(curl) {
+  CURLcode res;
+  curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
+
+  /* typically CONNECT is used to do HTTPS over HTTP proxies */
+  curl_easy_setopt(curl, CURLOPT_PROXY, "http://127.0.0.1");
+  res = curl_easy_perform(curl);
+  if(res == CURLE_OK) {
+    long code;
+    res = curl_easy_getinfo(curl, CURLINFO_HTTP_CONNECTCODE, &code);
+    if(!res && code)
+      printf("The CONNECT response code: %03ld\n", code);
+  }
+  curl_easy_cleanup(curl);
+}
+.fi
 .SH AVAILABILITY
 Added in 7.10.7
 .SH RETURN VALUE
index eccff500c55bb835e3ea101d7858d2133f9480b7..ae1ddae99048a36a3a2e639610a829c40b580b86 100644 (file)
@@ -5,7 +5,7 @@
 .\" *                            | (__| |_| |  _ <| |___
 .\" *                             \___|\___/|_| \_\_____|
 .\" *
-.\" * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
 .\" *
 .\" * This software is licensed as described in the file COPYING, which
 .\" * you should have received as part of this distribution. The terms
@@ -37,7 +37,22 @@ to make persistent connections to save time.
 .SH PROTOCOLS
 All
 .SH EXAMPLE
-TODO
+.nf
+CURL *curl = curl_easy_init();
+if(curl) {
+  CURLcode res;
+  curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
+  curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
+  res = curl_easy_perform(curl);
+  if(res == CURLE_OK) {
+    long connects;
+    res = curl_easy_getinfo(curl, CURLINFO_NUM_CONNECTS, &connects);
+    if(res)
+      printf("It needed %d connects\n", connects);
+  }
+  curl_easy_cleanup(curl);
+}
+.fi
 .SH AVAILABILITY
 Added in 7.12.3
 .SH RETURN VALUE