Commit 8e4fb01e authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

transfer-encoding: added new option and cmdline

Added CURLOPT_TRANSFER_ENCODING as the option to set to request Transfer
Encoding in HTTP requests (if built zlib enabled). I also renamed
CURLOPT_ENCODING to CURLOPT_ACCEPT_ENCODING (while keeping the old name
around) to reduce the confusion when we have to encoding options for
HTTP.

--tr-encoding is now the new command line option for curl to request
this, and thus I updated the test cases accordingly.
parent ebb37eac
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -282,6 +282,7 @@ CURLOPTTYPE_FUNCTIONPOINT 7.1
CURLOPTTYPE_LONG                7.1
CURLOPTTYPE_OBJECTPOINT         7.1
CURLOPTTYPE_OFF_T               7.11.0
CURLOPT_ACCEPT_ENCODING         7.21.6
CURLOPT_ADDRESS_SCOPE           7.19.0
CURLOPT_APPEND                  7.17.0
CURLOPT_AUTOREFERER             7.1
@@ -485,6 +486,7 @@ CURLOPT_TLSAUTH_PASSWORD 7.21.4
CURLOPT_TLSAUTH_TYPE            7.21.4
CURLOPT_TLSAUTH_USERNAME        7.21.4
CURLOPT_TRANSFERTEXT            7.1.1
CURLOPT_TRANSFER_ENCODING       7.21.6
CURLOPT_UNRESTRICTED_AUTH       7.10.4
CURLOPT_UPLOAD                  7.1
CURLOPT_URL                     7.1
+17 −3
Original line number Diff line number Diff line
@@ -517,7 +517,8 @@ typedef enum {
#ifndef CURL_NO_OLDIES /* define this to test if your app builds with all
                          the obsolete stuff removed! */

/* Backwards compatibility with older names */
/*  compatibility with older names */
#define CURLOPT_ENCODING CURLOPT_ACCEPT_ENCODING

/* The following were added in 7.21.5, April 2011 */
#define CURLE_UNKNOWN_TELNET_OPTION CURLE_UNKNOWN_OPTION
@@ -1103,8 +1104,9 @@ typedef enum {
  CINIT(PROXYTYPE, LONG, 101),

  /* Set the Accept-Encoding string. Use this to tell a server you would like
     the response to be compressed. */
  CINIT(ENCODING, OBJECTPOINT, 102),
     the response to be compressed. Before 7.21.6, this was known as
     CURLOPT_ENCODING */
  CINIT(ACCEPT_ENCODING, OBJECTPOINT, 102),

  /* Set pointer to private data */
  CINIT(PRIVATE, OBJECTPOINT, 103),
@@ -1462,6 +1464,18 @@ typedef enum {
  /* Set authentication type for authenticated TLS */
  CINIT(TLSAUTH_TYPE, OBJECTPOINT, 206),

  /* Set to 1 to enable the "TE:" header in HTTP requests to ask for
     compressed transfer-encoded responses. Set to 0 to disable the use of TE:
     in outgoing requests. The current default is 0, but it might change in a
     future libcurl release.

     libcurl will ask for the compressed methods it knows of, and if that
     isn't any, it will not ask for transfer-encoding at all even if this
     option is set to 1.

  */
  CINIT(TRANSFER_ENCODING, LONG, 207),

  CURLOPT_LASTENTRY /* the last unused */
} CURLoption;

+2 −2
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
 * Copyright (C) 1998 - 2011, 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
@@ -224,7 +224,7 @@ _CURL_WARNING(_curl_easy_getinfo_err_curl_slist,
   (option) == CURLOPT_PROXYUSERNAME ||                                       \
   (option) == CURLOPT_PROXYPASSWORD ||                                       \
   (option) == CURLOPT_NOPROXY ||                                             \
   (option) == CURLOPT_ENCODING ||                                            \
   (option) == CURLOPT_ACCEPT_ENCODING ||                                     \
   (option) == CURLOPT_REFERER ||                                             \
   (option) == CURLOPT_USERAGENT ||                                           \
   (option) == CURLOPT_COOKIE ||                                              \
+13 −6
Original line number Diff line number Diff line
@@ -1733,21 +1733,28 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
      return CURLE_OUT_OF_MEMORY;
  }

  if(Curl_checkheaders(data, "TE:")) {
    /* When we insert a TE: header in the request, we must also insert TE in a
       Connection: header, so we need to merge the custom provided Connection:
       header and prevent the original to get sent */
#ifdef HAVE_LIBZ
  /* we only consider transfer-encoding magic if libz support is built-in */

  if(!Curl_checkheaders(data, "TE:") && data->set.http_transfer_encoding) {
    /* When we are to insert a TE: header in the request, we must also insert
       TE in a Connection: header, so we need to merge the custom provided
       Connection: header and prevent the original to get sent. Note that if
       the user has inserted his/hers own TE: header we don't do this magic
       but then assume that the user will handle it all! */
    char *cptr = Curl_checkheaders(data, "Connection:");
#define TE_HEADER "TE: gzip\r\n"

    Curl_safefree(conn->allocptr.te);

    /* Create the (updated) Connection: header */
    conn->allocptr.te = cptr? aprintf("%s, TE\r\n", cptr):
      strdup("Connection: TE\r\n");
    conn->allocptr.te = cptr? aprintf("%s, TE\r\n" TE_HEADER, cptr):
      strdup("Connection: TE\r\n" TE_HEADER);

    if(!conn->allocptr.te)
      return CURLE_OUT_OF_MEMORY;
  }
#endif

  ptr = Curl_checkheaders(data, "Transfer-Encoding:");
  if(ptr) {
+5 −1
Original line number Diff line number Diff line
@@ -1076,7 +1076,7 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
    data->set.http_auto_referer = (bool)(0 != va_arg(param, long));
    break;

  case CURLOPT_ENCODING:
  case CURLOPT_ACCEPT_ENCODING:
    /*
     * String to use at the value of Accept-Encoding header.
     *
@@ -1092,6 +1092,10 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
                       (char *) ALL_CONTENT_ENCODINGS: argptr);
    break;

  case CURLOPT_TRANSFER_ENCODING:
    data->set.http_transfer_encoding = (bool)(0 != va_arg(param, long));
    break;

  case CURLOPT_FOLLOWLOCATION:
    /*
     * Follow Location: header hints on a HTTP-server.
Loading