]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
The tagging of application/x-www-form-urlencoded POST body data sent
authorDan Fandrich <dan@coneharvesters.com>
Fri, 13 Oct 2006 21:02:27 +0000 (21:02 +0000)
committerDan Fandrich <dan@coneharvesters.com>
Fri, 13 Oct 2006 21:02:27 +0000 (21:02 +0000)
to the CURLOPT_DEBUGFUNCTION callback has been fixed (it was erroneously
included as part of the header).  A message was also added to the
command line tool to show when data is being sent, enabled when
--verbose is used.

CHANGES
RELEASE-NOTES
lib/http.c
src/main.c

diff --git a/CHANGES b/CHANGES
index b94055d8813b703756863264d2af5d6c8dfadc82..6e2d9e32a6ea9fbe1c7556b0bd01fb884eda4bae 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,13 @@
 
                                   Changelog
 
+Dan F (13 October 2006)
+- The tagging of application/x-www-form-urlencoded POST body data sent
+  to the CURLOPT_DEBUGFUNCTION callback has been fixed (it was erroneously
+  included as part of the header).  A message was also added to the
+  command line tool to show when data is being sent, enabled when
+  --verbose is used.
+
 Daniel (12 October 2006)
 - Starting now, adding an easy handle to a multi stack that was already added
   to a multi stack will cause CURLM_BAD_EASY_HANDLE to get returned.
index 77fccaa72be4cc6f5a62343969c49c88ba87d702..f44ce15a84e16a1cd86dbdd09d84bcb72ff9f0f3 100644 (file)
@@ -47,6 +47,8 @@ This release includes the following bugfixes:
  o (HTTP) Expect: header disabling work better
  o (HTTP) "Expect: 100-continue" disable on second POST on re-used connection
  o src/config.h.in is fixed
+ o (HTTP) POST data logged to the debug callback function is now correctly
+   tagged as data, not header
 
 Other curl-related news:
 
@@ -66,6 +68,6 @@ advice from friends like these:
  Domenico Andreoli, Armel Asselin, Gisle Vanem, Yang Tse, Andrew Biggs,
  Peter Sylvester, David McCreedy, Dmitriy Sergeyev, Dmitry Rechkin,
  Jari Sundell, Ravi Pratap, Michele Bini, Jeff Pohlmeyer, Michael Wallner,
- Mike Protts, Cory Nelson, Bernard Leak, Bogdan Nicula
+ Mike Protts, Cory Nelson, Bernard Leak, Bogdan Nicula, Dan Fandrich
 
         Thanks! (and sorry if I forgot to mention someone)
index 596a380d7d442f577691aa1689d959f6da66a1b1..12c7741643e76e8734ae1b264307f5f88c888ed0 100644 (file)
@@ -573,11 +573,11 @@ CURLcode Curl_http_input_auth(struct connectdata *conn,
     start++;
 
   /*
-   * Here we check if we want the specific single authentiction (using ==) and
+   * Here we check if we want the specific single authentication (using ==) and
    * if we do, we initiate usage of it.
    *
    * If the provided authentication is wanted as one out of several accepted
-   * types (using &), we OR this authenticaion type to the authavail
+   * types (using &), we OR this authentication type to the authavail
    * variable.
    */
 
@@ -840,7 +840,8 @@ send_buffer *add_buffer_init(void)
 }
 
 /*
- * add_buffer_send() sends a buffer and frees all associated memory.
+ * add_buffer_send() sends a header buffer and frees all associated memory.
+ * Body data may be appended to the header data if desired.
  *
  * Returns CURLcode
  */
@@ -849,7 +850,10 @@ CURLcode add_buffer_send(send_buffer *in,
                          struct connectdata *conn,
                          long *bytes_written, /* add the number of sent
                                                  bytes to this counter */
+                         int included_body_bytes, /* how much of the buffer
+                                        contains body data (for log tracing) */
                          int socketindex)
+
 {
   ssize_t amount;
   CURLcode res;
@@ -894,9 +898,14 @@ CURLcode add_buffer_send(send_buffer *in,
 
   if(CURLE_OK == res) {
 
-    if(conn->data->set.verbose)
+    if(conn->data->set.verbose) {
       /* this data _may_ contain binary stuff */
-      Curl_debug(conn->data, CURLINFO_HEADER_OUT, ptr, amount, conn);
+      Curl_debug(conn->data, CURLINFO_HEADER_OUT, ptr,
+                 amount-included_body_bytes, conn);
+      if (included_body_bytes)
+        Curl_debug(conn->data, CURLINFO_DATA_OUT,
+                   ptr+amount-included_body_bytes, included_body_bytes, conn);
+    }
 
     *bytes_written += amount;
 
@@ -1173,7 +1182,7 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
         if(CURLE_OK == result)
           /* Now send off the request */
           result = add_buffer_send(req_buffer, conn,
-                                   &data->info.request_size, sockindex);
+                                   &data->info.request_size, 0, sockindex);
       }
       if(result)
         failf(data, "Failed sending CONNECT to proxy");
@@ -1360,7 +1369,7 @@ CURLcode Curl_http_connect(struct connectdata *conn, bool *done)
   /* If we are not using a proxy and we want a secure connection, perform SSL
    * initialization & connection now.  If using a proxy with https, then we
    * must tell the proxy to CONNECT to the host we want to talk to.  Only
-   * after the connect has occured, can we start talking SSL
+   * after the connect has occurred, can we start talking SSL
    */
 
   if(conn->bits.tunnel_proxy && conn->bits.httpproxy) {
@@ -1594,6 +1603,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
   char *request;
   Curl_HttpReq httpreq = data->set.httpreq;
   char *addcookies = NULL;
+  int included_body = 0;
 
   /* Always consider the DO phase done after this function call, even if there
      may be parts of the request that is not yet sent, since we can deal with
@@ -1612,7 +1622,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
   else
     http = data->reqdata.proto.http;
 
-  /* We default to persistant connections */
+  /* We default to persistent connections */
   conn->bits.close = FALSE;
 
   if ( (conn->protocol&(PROT_HTTP|PROT_FTP)) &&
@@ -2096,7 +2106,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
           return result;
 
         result = add_buffer_send(req_buffer, conn,
-                                 &data->info.request_size, FIRSTSOCKET);
+                                 &data->info.request_size, 0, FIRSTSOCKET);
         if(result)
           failf(data, "Failed sending POST request");
         else
@@ -2159,7 +2169,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
 
       /* fire away the whole request to the server */
       result = add_buffer_send(req_buffer, conn,
-                               &data->info.request_size, FIRSTSOCKET);
+                               &data->info.request_size, 0, FIRSTSOCKET);
       if(result)
         failf(data, "Failed sending POST request");
       else
@@ -2203,7 +2213,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
 
       /* this sends the buffer and frees all the buffer resources */
       result = add_buffer_send(req_buffer, conn,
-                               &data->info.request_size, FIRSTSOCKET);
+                               &data->info.request_size, 0, FIRSTSOCKET);
       if(result)
         failf(data, "Failed sending PUT request");
       else
@@ -2280,6 +2290,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
                already now to reduce the number if send() calls */
             result = add_buffer(req_buffer, data->set.postfields,
                                 (size_t)postsize);
+            included_body = postsize;
           }
           else {
             /* Append the POST data chunky-style */
@@ -2291,6 +2302,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
               result = add_buffer(req_buffer,
                                   "\r\n0\r\n\r\n", 7); /* end of a chunked
                                                           transfer stream */
+            included_body = postsize + 7;
           }
           if(result)
             return result;
@@ -2324,8 +2336,8 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
         }
       }
       /* issue the request */
-      result = add_buffer_send(req_buffer, conn,
-                               &data->info.request_size, FIRSTSOCKET);
+      result = add_buffer_send(req_buffer, conn, &data->info.request_size,
+                               included_body, FIRSTSOCKET);
 
       if(result)
         failf(data, "Failed sending HTTP POST request");
@@ -2342,7 +2354,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
 
       /* issue the request */
       result = add_buffer_send(req_buffer, conn,
-                               &data->info.request_size, FIRSTSOCKET);
+                               &data->info.request_size, 0, FIRSTSOCKET);
 
       if(result)
         failf(data, "Failed sending HTTP request");
index 0798364fb022cac5fa7e4ec2eb994f8d8085a65f..af3f4355f52cca99d8b4f2633d4e1a0c1f19e8c2 100644 (file)
@@ -2986,11 +2986,12 @@ int my_trace(CURL *handle, curl_infotype type,
      * own.
      */
     static const char * const s_infotype[] = {
-      "*", "<", ">"
+      "*", "<", ">", "{", "}", "{", "}"
     };
     size_t i;
     size_t st=0;
     static bool newl = FALSE;
+    static bool traced_data = FALSE;
 
     switch(type) {
     case CURLINFO_HEADER_OUT:
@@ -3008,20 +3009,35 @@ int my_trace(CURL *handle, curl_infotype type,
       if(!newl)
         fprintf(config->trace_stream, "%s%s ", timebuf, s_infotype[type]);
       fwrite(data+st, i-st+1, 1, config->trace_stream);
+      newl = (bool)(size && (data[size-1] != '\n'));
+      traced_data = FALSE;
       break;
     case CURLINFO_TEXT:
     case CURLINFO_HEADER_IN:
       if(!newl)
         fprintf(config->trace_stream, "%s%s ", timebuf, s_infotype[type]);
       fwrite(data, size, 1, config->trace_stream);
+      newl = (bool)(size && (data[size-1] != '\n'));
+      traced_data = FALSE;
+      break;
+    case CURLINFO_DATA_OUT:
+    case CURLINFO_DATA_IN:
+    case CURLINFO_SSL_DATA_IN:
+    case CURLINFO_SSL_DATA_OUT:
+      if(!traced_data) {
+       if(!newl)
+         fprintf(config->trace_stream, "%s%s ", timebuf, s_infotype[type]);
+       fprintf(config->trace_stream, "[data not shown]\n");
+       newl = FALSE;
+        traced_data = TRUE;
+      }
       break;
     default: /* nada */
       newl = FALSE;
+      traced_data = FALSE;
       break;
     }
 
-    newl = (bool)(size && (data[size-1] != '\n'));
-
     return 0;
   }