>> Olivier is correct, this is what I am seeing, also.  In order to view the
>> final status code, I had to implement a header function and manually parse
>> out the 2nd response code when the request is completed.  Since, per the
>> spec, a final status code is required in all cases, as far as I can tell, it
>> seems reasonable to make the 2nd response code the value returned from
>> CURLINFO_RESPONSE_CODE in all cases.
>
> I can only agree and I consider this a bug.

I had a look at this bug today and I could not reproduce it. I have
attached the test I run. I don't see the 100 response code that you
mentioned which likely means that I am not testing the same
conditions.

Olivier and Jorge, could you give us more info about your libcURL
version and some instructions to reproduce this on our side? Even
better do you have a reduced program that shows the bad behavior?

Thanks!
Julien
From 1c196bedee6b243272cc7fd5550dcd8a81691067 Mon Sep 17 00:00:00 2001
From: Julien Chaffraix <[email protected]>
Date: Sun, 20 Mar 2011 09:25:11 -0700
Subject: [PATCH] test: Check CURLINFO_RESPONSE_CODE after 100 Continue

Adding a test case to cover the case mentioned in the thread:
http://curl.haxx.se/mail/lib-2011-03/0159.html
---
 tests/data/Makefile.am     |    2 +-
 tests/data/test1204        |   61 +++++++++++++++++++
 tests/libtest/Makefile.inc |    4 +-
 tests/libtest/lib1204.c    |  143 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 208 insertions(+), 2 deletions(-)
 create mode 100644 tests/data/test1204
 create mode 100644 tests/libtest/lib1204.c

diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
index e75949f..94cadf2 100644
--- a/tests/data/Makefile.am
+++ b/tests/data/Makefile.am
@@ -71,7 +71,7 @@ EXTRA_DIST = test1 test108 test117 test127 test20 test27 test34 test46	   \
  test1203 test1117 test1118 test1119 test1120 test1300 test1301 test1302 \
  test1303 test320 test321 test322 test323 test324 test1121 test581 test580 \
  test1304 test1305 test1306 test1307 test582 test583 test808 test809       \
- test810 test811 test812 test813
+ test810 test811 test812 test813 test1204
 
 filecheck:
 	@mkdir test-place; \
diff --git a/tests/data/test1204 b/tests/data/test1204
new file mode 100644
index 0000000..d0effcf
--- /dev/null
+++ b/tests/data/test1204
@@ -0,0 +1,61 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP POST
+</keywords>
+</info>
+#
+# Server-side
+<reply>
+<datacheck>
+HTTP/1.1 100 Continue
+Server: Microsoft-IIS/5.0
+Date: Sun, 03 Apr 2005 14:57:45 GMT
+X-Powered-By: ASP.NET
+
+HTTP/1.1 401 authentication please swsbounce
+Server: Microsoft-IIS/6.0
+WWW-Authenticate: Digest realm="testrealm", nonce="1053604144"
+Content-Type: text/html; charset=iso-8859-1
+Content-Length: 0
+
+</datacheck>
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+# tool is what to use instead of 'curl'
+<tool>
+lib1204
+</tool>
+
+ <name>
+send HTTP POST Expect 100-Continue CURLINFO_RESPONSE_CODE
+ </name>
+ <command>
+http://%HOSTIP:%HTTPPORT/565
+</command>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<protocol>
+POST /565 HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+Accept: */*
+Transfer-Encoding: chunked
+Content-Type: application/x-www-form-urlencoded
+Expect: 100-continue
+
+3
+one
+0
+
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc
index a210cbf..17858b4 100644
--- a/tests/libtest/Makefile.inc
+++ b/tests/libtest/Makefile.inc
@@ -12,7 +12,7 @@ noinst_PROGRAMS = chkhostname \
   lib579 lib529 lib530 lib532 lib533 lib536 lib537 lib540 lib541 lib542	\
   lib543 lib544 lib545 lib547 lib548 lib549 lib552 lib553 lib554 lib555	\
   lib556 lib539 lib557 lib560 lib562 lib564 lib565 lib566 lib567 lib568	\
-  lib569 lib570 lib571 lib572 lib573 lib582 lib583
+  lib569 lib570 lib571 lib572 lib573 lib582 lib583 lib1204
 
 chkhostname_SOURCES = chkhostname.c $(top_srcdir)/lib/curl_gethostname.c
 chkhostname_LDADD = @CURL_NETWORK_LIBS@
@@ -160,3 +160,5 @@ lib579_SOURCES = lib579.c $(SUPPORTFILES)
 lib582_SOURCES = lib582.c $(SUPPORTFILES) $(TESTUTIL)
 
 lib583_SOURCES = lib583.c $(SUPPORTFILES)
+
+lib1204_SOURCES = lib1204.c $(SUPPORTFILES)
diff --git a/tests/libtest/lib1204.c b/tests/libtest/lib1204.c
new file mode 100644
index 0000000..721b400
--- /dev/null
+++ b/tests/libtest/lib1204.c
@@ -0,0 +1,143 @@
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2011, Daniel Stenberg, <[email protected]>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+#include "test.h"
+
+#include "memdebug.h"
+
+static const char *post[]={
+  "one",
+  NULL
+};
+
+
+struct WriteThis {
+  CURL *curl;
+  int counter;
+};
+
+static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
+{
+  struct WriteThis *pooh = (struct WriteThis *)userp;
+  const char *data;
+  long response_code;
+
+  if(size*nmemb < 1)
+    return 0;
+
+  if (pooh->counter) {
+    curl_easy_getinfo(pooh->curl, CURLINFO_RESPONSE_CODE, &response_code);
+    fprintf(stderr, "curl_easy_getinfo in read_callback %ld\n", response_code);
+    /* For some reason, we don't see the "100 Continue" response here. */
+    if (response_code != 0)
+      return -1;
+  }
+
+  data = post[pooh->counter];
+
+  if(data) {
+    size_t len = strlen(data);
+    memcpy(ptr, data, len);
+    pooh->counter++; /* advance pointer */
+    return len;
+  }
+
+  return 0; /* no more data left to deliver */
+}
+
+int test(char *URL)
+{
+  CURL *curl;
+  CURLcode res=CURLE_OK;
+  struct curl_slist *slist = NULL;
+  struct WriteThis pooh;
+  long response_code = 0;
+  pooh.counter = 0;
+
+  if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
+    fprintf(stderr, "curl_global_init() failed\n");
+    return TEST_ERR_MAJOR_BAD;
+  }
+
+  if ((curl = curl_easy_init()) == NULL) {
+    fprintf(stderr, "curl_easy_init() failed\n");
+    curl_global_cleanup();
+    return TEST_ERR_MAJOR_BAD;
+  }
+
+  pooh.curl = curl;
+
+  slist = curl_slist_append(slist, "Transfer-Encoding: chunked");
+  if (slist == NULL) {
+    fprintf(stderr, "curl_slist_append() failed\n");
+    curl_easy_cleanup(curl);
+    curl_global_cleanup();
+    return TEST_ERR_MAJOR_BAD;
+  }
+
+  /* First set the URL that is about to receive our POST. */
+  test_setopt(curl, CURLOPT_URL, URL);
+
+  /* Now specify we want to POST data */
+  test_setopt(curl, CURLOPT_POST, 1L);
+
+#ifdef CURL_DOES_CONVERSIONS
+  /* Convert the POST data to ASCII */
+  test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
+#endif
+
+  /* we want to use our own read function */
+  test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
+
+  /* pointer to pass to our read function */
+  test_setopt(curl, CURLOPT_INFILE, &pooh);
+
+  /* get verbose debug output please */
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
+
+  /* include headers in the output */
+  test_setopt(curl, CURLOPT_HEADER, 1L);
+
+  /* enforce chunked transfer by setting the header */
+  test_setopt(curl, CURLOPT_HTTPHEADER, slist);
+
+  /* Perform the request, res will get the return code */
+  res = curl_easy_perform(curl);
+
+  /* Test the value of CURLINFO_RESPONSE_CODE */
+  if (res == CURLE_OK) {
+    res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
+    fprintf(stderr, "curl_easy_getinfo %ld\n", response_code);
+    if (response_code != 401)
+      res = TEST_ERR_MAJOR_BAD;
+  }
+test_cleanup:
+
+  /* clean up the headers list */
+  if(slist)
+    curl_slist_free_all(slist);
+
+  /* always cleanup */
+  curl_easy_cleanup(curl);
+  curl_global_cleanup();
+
+  return res;
+}
-- 
1.7.1

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to