From 536f5f442e779b29ff2f28cd26a847058cdd6ed1 Mon Sep 17 00:00:00 2001
From: Daniel Stenberg <daniel@haxx.se>
Date: Sun, 13 Dec 2015 09:24:08 +0100
Subject: [PATCH 2/2] curl: use 2TLS by default

Make this the default for the curl tool (if built with HTTP/2 powers
enabled) unless a specific HTTP version is requested on the command
line.

This should allow more users to get HTTP/2 powers without having to
change anything.
---
 src/tool_operate.c  | 4 +++-
 src/tool_setopt.c   | 2 ++
 tests/data/test1400 | 5 +++--
 tests/data/test1401 | 5 +++--
 tests/data/test1402 | 5 +++--
 tests/data/test1403 | 5 +++--
 tests/data/test1404 | 5 +++--
 tests/data/test1405 | 5 +++--
 tests/data/test1406 | 5 +++--
 tests/data/test1407 | 5 +++--
 tests/data/test1420 | 5 +++--
 11 files changed, 32 insertions(+), 19 deletions(-)

diff --git a/src/tool_operate.c b/src/tool_operate.c
index d5177d9..e5506c6 100644
--- a/src/tool_operate.c
+++ b/src/tool_operate.c
@@ -954,13 +954,15 @@ static CURLcode operate_do(struct GlobalConfig *global,
           }
 
           /* new in libcurl 7.5 */
           my_setopt(curl, CURLOPT_MAXREDIRS, config->maxredirs);
 
-          /* new in libcurl 7.9.1 */
           if(config->httpversion)
             my_setopt_enum(curl, CURLOPT_HTTP_VERSION, config->httpversion);
+          else if(curlinfo->features & CURL_VERSION_HTTP2) {
+            my_setopt_enum(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2TLS);
+          }
 
           /* new in libcurl 7.10.6 (default is Basic) */
           if(config->authtype)
             my_setopt_bitmask(curl, CURLOPT_HTTPAUTH, (long)config->authtype);
 
diff --git a/src/tool_setopt.c b/src/tool_setopt.c
index e11f527..ff8d407 100644
--- a/src/tool_setopt.c
+++ b/src/tool_setopt.c
@@ -68,10 +68,12 @@ const NameValueUnsigned setopt_nv_CURLAUTH[] = {
 
 const NameValue setopt_nv_CURL_HTTP_VERSION[] = {
   NV(CURL_HTTP_VERSION_NONE),
   NV(CURL_HTTP_VERSION_1_0),
   NV(CURL_HTTP_VERSION_1_1),
+  NV(CURL_HTTP_VERSION_2_0),
+  NV(CURL_HTTP_VERSION_2TLS),
   NVEND,
 };
 
 const NameValue setopt_nv_CURL_SSLVERSION[] = {
   NV(CURL_SSLVERSION_DEFAULT),
diff --git a/tests/data/test1400 b/tests/data/test1400
index 72989c4..be458bd 100644
--- a/tests/data/test1400
+++ b/tests/data/test1400
@@ -44,14 +44,15 @@ Host: %HOSTIP:%HTTPPORT
 Accept: */*
 
 </protocol>
 <stripfile>
 s/(USERAGENT, \")[^\"]+/${1}stripped/
-# CURLOPT_SSL_VERIFYPEER and SSH_KNOWNHOSTS vary with configurations - just
-# ignore them
+# CURLOPT_SSL_VERIFYPEER, SSH_KNOWNHOSTS and HTTP_VERSION vary with
+# configurations - just ignore them
 $_ = '' if /CURLOPT_SSL_VERIFYPEER/
 $_ = '' if /CURLOPT_SSH_KNOWNHOSTS/
+$_ = '' if /CURLOPT_HTTP_VERSION/
 </stripfile>
 <file name="log/test1400.c" mode="text">
 /********* Sample code generated by the curl command line tool **********
  * All curl_easy_setopt() options are documented at:
  * http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
diff --git a/tests/data/test1401 b/tests/data/test1401
index d10cac2..6144bd8 100644
--- a/tests/data/test1401
+++ b/tests/data/test1401
@@ -51,14 +51,15 @@ Cookie: chocolate=chip
 X-Files: Mulder
 X-Men: cyclops, iceman
 
 </protocol>
 <stripfile>
-# CURLOPT_SSL_VERIFYPEER and SSH_KNOWNHOSTS vary with configurations - just
-# ignore them
+# CURLOPT_SSL_VERIFYPEER, SSH_KNOWNHOSTS and HTTP_VERSION vary with
+# configurations - just ignore them
 $_ = '' if /CURLOPT_SSL_VERIFYPEER/
 $_ = '' if /CURLOPT_SSH_KNOWNHOSTS/
+$_ = '' if /CURLOPT_HTTP_VERSION/
 </stripfile>
 <file name="log/test1401.c" mode="text">
 /********* Sample code generated by the curl command line tool **********
  * All curl_easy_setopt() options are documented at:
  * http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
diff --git a/tests/data/test1402 b/tests/data/test1402
index c3bf834..00395fc 100644
--- a/tests/data/test1402
+++ b/tests/data/test1402
@@ -49,14 +49,15 @@ Content-Type: application/x-www-form-urlencoded
 foo=bar&baz=quux
 </protocol>
 <stripfile>
 # curl's default user-agent varies with version, libraries etc.
 s/(USERAGENT, \")[^\"]+/${1}stripped/
-# CURLOPT_SSL_VERIFYPEER and SSH_KNOWNHOSTS vary with configurations - just
-# ignore them
+# CURLOPT_SSL_VERIFYPEER, SSH_KNOWNHOSTS and HTTP_VERSION vary with
+# configurations - just ignore them
 $_ = '' if /CURLOPT_SSL_VERIFYPEER/
 $_ = '' if /CURLOPT_SSH_KNOWNHOSTS/
+$_ = '' if /CURLOPT_HTTP_VERSION/
 </stripfile>
 <file name="log/test1402.c" mode="text">
 /********* Sample code generated by the curl command line tool **********
  * All curl_easy_setopt() options are documented at:
  * http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
diff --git a/tests/data/test1403 b/tests/data/test1403
index 3ec7dd0..85188d8 100644
--- a/tests/data/test1403
+++ b/tests/data/test1403
@@ -46,14 +46,15 @@ Accept: */*
 
 </protocol>
 <stripfile>
 # curl's default user-agent varies with version, libraries etc.
 s/(USERAGENT, \")[^\"]+/${1}stripped/
-# CURLOPT_SSL_VERIFYPEER and SSH_KNOWNHOSTS vary with configurations - just
-# ignore them
+# CURLOPT_SSL_VERIFYPEER, SSH_KNOWNHOSTS and HTTP_VERSION vary with
+# configurations - just ignore them
 $_ = '' if /CURLOPT_SSL_VERIFYPEER/
 $_ = '' if /CURLOPT_SSH_KNOWNHOSTS/
+$_ = '' if /CURLOPT_HTTP_VERSION/
 </stripfile>
 <file name="log/test1403.c" mode="text">
 /********* Sample code generated by the curl command line tool **********
  * All curl_easy_setopt() options are documented at:
  * http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
diff --git a/tests/data/test1404 b/tests/data/test1404
index 4415697..0f59c49 100644
--- a/tests/data/test1404
+++ b/tests/data/test1404
@@ -81,14 +81,15 @@ dummy data
 ------------------------------9ef8d6205763--
 </protocol>
 <stripfile>
 # curl's default user-agent varies with version, libraries etc.
 s/(USERAGENT, \")[^\"]+/${1}stripped/
-# CURLOPT_SSL_VERIFYPEER and SSH_KNOWNHOSTS vary with configurations - just
-# ignore them
+# CURLOPT_SSL_VERIFYPEER, SSH_KNOWNHOSTS and HTTP_VERSION vary with
+# configurations - just ignore them
 $_ = '' if /CURLOPT_SSL_VERIFYPEER/
 $_ = '' if /CURLOPT_SSH_KNOWNHOSTS/
+$_ = '' if /CURLOPT_HTTP_VERSION/
 </stripfile>
 <file name="log/test1404.c" mode="text">
 /********* Sample code generated by the curl command line tool **********
  * All curl_easy_setopt() options are documented at:
  * http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
diff --git a/tests/data/test1405 b/tests/data/test1405
index 38bfd5c..5868afa 100644
--- a/tests/data/test1405
+++ b/tests/data/test1405
@@ -125,12 +125,13 @@ int main(int argc, char *argv[])
 <stripfile>
 # CURLOPT_USERAGENT and CURLOPT_MAXREDIRS requires HTTP protocol
 # support, IOW depends on configuration - just ignore these.
 $_ = '' if /CURLOPT_USERAGENT/
 $_ = '' if /CURLOPT_MAXREDIRS/
-# CURLOPT_SSL_VERIFYPEER and SSH_KNOWNHOSTS vary with configurations - just
-# ignore them
+# CURLOPT_SSL_VERIFYPEER, SSH_KNOWNHOSTS and HTTP_VERSION vary with
+# configurations - just ignore them
 $_ = '' if /CURLOPT_SSL_VERIFYPEER/
 $_ = '' if /CURLOPT_SSH_KNOWNHOSTS/
+$_ = '' if /CURLOPT_HTTP_VERSION/
 </stripfile>
 </verify>
 </testcase>
diff --git a/tests/data/test1406 b/tests/data/test1406
index c80459f..8c6de5c 100644
--- a/tests/data/test1406
+++ b/tests/data/test1406
@@ -114,12 +114,13 @@ int main(int argc, char *argv[])
 /**** End of sample code ****/
 </file>
 <stripfile>
 # curl's default user-agent varies with version, libraries etc.
 s/(USERAGENT, \")[^\"]+/${1}stripped/
-# CURLOPT_SSL_VERIFYPEER and SSH_KNOWNHOSTS vary with configurations - just
-# ignore them
+# CURLOPT_SSL_VERIFYPEER, SSH_KNOWNHOSTS and HTTP_VERSION vary with
+# configurations - just ignore them
 $_ = '' if /CURLOPT_SSL_VERIFYPEER/
 $_ = '' if /CURLOPT_SSH_KNOWNHOSTS/
+$_ = '' if /CURLOPT_HTTP_VERSION/
 </stripfile>
 </verify>
 </testcase>
diff --git a/tests/data/test1407 b/tests/data/test1407
index e84463a..8ec9b44 100644
--- a/tests/data/test1407
+++ b/tests/data/test1407
@@ -92,12 +92,13 @@ int main(int argc, char *argv[])
 /**** End of sample code ****/
 </file>
 <stripfile>
 # curl's default user-agent varies with version, libraries etc.
 s/(USERAGENT, \")[^\"]+/${1}stripped/
-# CURLOPT_SSL_VERIFYPEER and SSH_KNOWNHOSTS vary with configurations - just
-# ignore them
+# CURLOPT_SSL_VERIFYPEER, SSH_KNOWNHOSTS and HTTP_VERSION vary with
+# configurations - just ignore them
 $_ = '' if /CURLOPT_SSL_VERIFYPEER/
 $_ = '' if /CURLOPT_SSH_KNOWNHOSTS/
+$_ = '' if /CURLOPT_HTTP_VERSION/
 </stripfile>
 </verify>
 </testcase>
diff --git a/tests/data/test1420 b/tests/data/test1420
index 79ca675..8894045 100644
--- a/tests/data/test1420
+++ b/tests/data/test1420
@@ -97,12 +97,13 @@ int main(int argc, char *argv[])
 /**** End of sample code ****/
 </file>
 <stripfile>
 # curl's default user-agent varies with version, libraries etc.
 s/(USERAGENT, \")[^\"]+/${1}stripped/
-# CURLOPT_SSL_VERIFYPEER and SSH_KNOWNHOSTS vary with configurations - just
-# ignore them
+# CURLOPT_SSL_VERIFYPEER, SSH_KNOWNHOSTS and HTTP_VERSION vary with
+# configurations - just ignore them
 $_ = '' if /CURLOPT_SSL_VERIFYPEER/
 $_ = '' if /CURLOPT_SSH_KNOWNHOSTS/
+$_ = '' if /CURLOPT_HTTP_VERSION/
 </stripfile>
 </verify>
 </testcase>
-- 
2.6.2

