cURL / Mailing Lists / curl-library / Single Mail

curl-library

[PATCH] transfer: make Expect: 100-continue timeout configurable.

From: Tiit Pikma <tiit.pikma_at_cyber.ee>
Date: Thu, 13 Feb 2014 11:49:27 +0200

Replaced the #define CURL_TIMEOUT_EXPECT_100 in transfer.c with
CURLOPT_EXPECT_100_TIMEOUT and CURLOPT_EXPECT_100_TIMEOUT_MS options to
make the timeout configurable.

---
 docs/libcurl/curl_easy_setopt.3 |  7 +++++++
 include/curl/curl.h             |  5 +++++
 lib/transfer.c                  |  8 +++-----
 lib/url.c                       | 14 ++++++++++++++
 lib/urldata.h                   |  2 ++
 5 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/docs/libcurl/curl_easy_setopt.3 b/docs/libcurl/curl_easy_setopt.3
index 9a18964..2c243f8 100644
--- a/docs/libcurl/curl_easy_setopt.3
+++ b/docs/libcurl/curl_easy_setopt.3
@@ -1649,6 +1649,13 @@ Pass a long to tell libcurl how to act on transfer decoding. If set to zero,
 transfer decoding will be disabled, if set to 1 it is enabled
 (default). libcurl does chunked transfer decoding by default unless this
 option is set to zero. (added in 7.16.2)
+.IP CURLOPT_EXPECT_100_TIMEOUT
+Pass a long to tell libcurl how long to wait in seconds for a server response
+with the HTTP status 100 (Continue) or 417 (Expectation Failed) after sending a
+HTTP request containing an Expect: 100-continue header. If this times out
+before a response is received, the request body is sent anyway.
+.IP CURLOPT_EXPECT_100_TIMEOUT_MS
+Same as \fICURLOPT_EXPECT_100_TIMEOUT\fP but takes milliseconds instead of seconds.
 .SH SMTP OPTIONS
 .IP CURLOPT_MAIL_FROM
 Pass a pointer to a zero terminated string as parameter. This should be used
diff --git a/include/curl/curl.h b/include/curl/curl.h
index b2c9ee0..c2282b3 100644
--- a/include/curl/curl.h
+++ b/include/curl/curl.h
@@ -1577,6 +1577,11 @@ typedef enum {
   /* Enable/disable TLS ALPN extension (http2 over ssl might fail without) */
   CINIT(SSL_ENABLE_ALPN, LONG, 226),
 
+  /* Time to wait for a response to a HTTP request containing an
+   * Expect: 100-continue header before sending the data anyway. */
+  CINIT(EXPECT_100_TIMEOUT, LONG, 227),
+  CINIT(EXPECT_100_TIMEOUT_MS, LONG, 228),
+
   CURLOPT_LASTENTRY /* the last unused */
 } CURLoption;
 
diff --git a/lib/transfer.c b/lib/transfer.c
index f996b0e..83727db 100644
--- a/lib/transfer.c
+++ b/lib/transfer.c
@@ -87,8 +87,6 @@
 /* The last #include file should be: */
 #include "memdebug.h"
 
-#define CURL_TIMEOUT_EXPECT_100 1000 /* counting ms here */
-
 /*
  * This function will call the read callback to fill our buffer with data
  * to upload.
@@ -839,7 +837,7 @@ static CURLcode readwrite_upload(struct SessionHandle *data,
           *didwhat &= ~KEEP_SEND;  /* we didn't write anything actually */
 
           /* set a timeout for the multi interface */
-          Curl_expire(data, CURL_TIMEOUT_EXPECT_100);
+          Curl_expire(data, data->set.expect_100_timeout);
           break;
         }
 
@@ -1075,7 +1073,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
       */
 
       long ms = Curl_tvdiff(k->now, k->start100);
-      if(ms >= CURL_TIMEOUT_EXPECT_100) {
+      if(ms >= data->set.expect_100_timeout) {
         /* we've waited long enough, continue anyway */
         k->exp100 = EXP100_SEND_DATA;
         k->keepon |= KEEP_SEND;
@@ -1969,7 +1967,7 @@ Curl_setup_transfer(
 
         /* Set a timeout for the multi interface. Add the inaccuracy margin so
            that we don't fire slightly too early and get denied to run. */
-        Curl_expire(data, CURL_TIMEOUT_EXPECT_100);
+        Curl_expire(data, data->set.expect_100_timeout);
       }
       else {
         if(data->state.expect100header)
diff --git a/lib/url.c b/lib/url.c
index 3f2112d..7bdcd6d 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -565,6 +565,8 @@ CURLcode Curl_init_userdefined(struct UserDefined *set)
 
   set->ssl_enable_npn = TRUE;
   set->ssl_enable_alpn = TRUE;
+
+  set->expect_100_timeout = 1000L; /* Wait for a second by default. */
   return res;
 }
 
@@ -1256,6 +1258,18 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
   }
   break;
 
+  case CURLOPT_EXPECT_100_TIMEOUT:
+    /*
+     * Time to wait for a response to a HTTP request containing an
+     * Expect: 100-continue header before sending the data anyway.
+     */
+    data->set.expect_100_timeout = va_arg(param, long) * 1000L;
+    break;
+
+  case CURLOPT_EXPECT_100_TIMEOUT_MS:
+    data->set.expect_100_timeout = va_arg(param, long);
+    break;
+
 #endif   /* CURL_DISABLE_HTTP */
 
   case CURLOPT_CUSTOMREQUEST:
diff --git a/lib/urldata.h b/lib/urldata.h
index 188e766..1ab7b94 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -1596,6 +1596,8 @@ struct UserDefined {
 
   bool ssl_enable_npn;  /* TLS NPN extension? */
   bool ssl_enable_alpn; /* TLS ALPN extension? */
+
+  long expect_100_timeout; /* in milliseconds */
 };
 
 struct Names {
-- 
1.8.5.3
--=-UGz1tz2/Q5rK9MhmkFRc
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
--=-UGz1tz2/Q5rK9MhmkFRc--
Received on 2001-09-17