From 000dacb617bcfa3ce52061422c736021a8cff37f Mon Sep 17 00:00:00 2001
From: Daniel Stenberg <daniel@haxx.se>
Date: Sat, 29 Aug 2015 23:56:28 +0200
Subject: [PATCH] curl: warn for pointless uses of -X

---
 src/tool_helpers.c | 23 +++++++++++++++++++++++
 src/tool_helpers.h |  5 ++++-
 src/tool_operate.c |  1 +
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/tool_helpers.c b/src/tool_helpers.c
index 2f74dc1..2edc8d3 100644
--- a/src/tool_helpers.c
+++ b/src/tool_helpers.c
@@ -87,5 +87,28 @@ int SetHTTPrequest(struct OperationConfig *config, HttpReq req, HttpReq *store)
         "You asked for both %s and %s.\n",
         reqname[req], reqname[*store]);
 
   return 1;
 }
+
+void customrequest_helper(struct OperationConfig *config, HttpReq req,
+                          char *method)
+{
+  /* this mirrors the HttpReq enum in tool_sdecls.h */
+  const char *dflt[]= {
+    "GET",
+    "GET",
+    "HEAD",
+    "POST",
+    "POST"
+  };
+
+  if(curl_strequal(method, dflt[req])) {
+    warnf(config->global, "Superfluous use of -X. --request, %s is already "
+          "inferred.\n", dflt[req]);
+  }
+  else if(curl_strequal(method, "head")) {
+    warnf(config->global,
+          "Setting custom HTTP method to HEAD may not work the way you "
+          "want.\n");
+  }
+}
diff --git a/src/tool_helpers.h b/src/tool_helpers.h
index 73bcfc7..117334c 100644
--- a/src/tool_helpers.h
+++ b/src/tool_helpers.h
@@ -5,11 +5,11 @@
  *  Project                     ___| | | |  _ \| |
  *                             / __| | | | |_) | |
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2015, 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
  * are also available at http://curl.haxx.se/docs/copyright.html.
  *
@@ -26,7 +26,10 @@
 const char *param2text(int res);
 
 int SetHTTPrequest(struct OperationConfig *config, HttpReq req,
                    HttpReq *store);
 
+void customrequest_helper(struct OperationConfig *config, HttpReq req,
+                          char *method);
+
 #endif /* HEADER_CURL_TOOL_HELPERS_H */
 
diff --git a/src/tool_operate.c b/src/tool_operate.c
index b3fa146..38d355d 100644
--- a/src/tool_operate.c
+++ b/src/tool_operate.c
@@ -1106,10 +1106,11 @@ static CURLcode operate_do(struct GlobalConfig *global,
 #endif
 
         my_setopt_enum(curl, CURLOPT_TIMECONDITION, (long)config->timecond);
         my_setopt(curl, CURLOPT_TIMEVALUE, (long)config->condtime);
         my_setopt_str(curl, CURLOPT_CUSTOMREQUEST, config->customrequest);
+        customrequest_helper(config, config->httpreq, config->customrequest);
         my_setopt(curl, CURLOPT_STDERR, global->errors);
 
         /* three new ones in libcurl 7.3: */
         my_setopt_str(curl, CURLOPT_INTERFACE, config->iface);
         my_setopt_str(curl, CURLOPT_KRBLEVEL, config->krblevel);
-- 
2.5.0

