From 02dd66a3923c2c77c0c06331185510a44b9854ca Mon Sep 17 00:00:00 2001
From: Darshit Shah <darnir@gmail.com>
Date: Tue, 5 Mar 2013 22:40:37 +0530
Subject: [PATCH] Add support for HTTP DELETE Action for RESTful Scripting.
 Signed-off-by: Darshit Shah <darnir@gmail.com>

---
 src/http.c    | 4 ++++
 src/init.c    | 4 +++-
 src/main.c    | 3 +++
 src/options.h | 1 +
 4 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/http.c b/src/http.c
index fdb0d7e..a636033 100644
--- a/src/http.c
+++ b/src/http.c
@@ -1767,6 +1767,10 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy,
       meth = "HEAD";
     else if (opt.post_file_name || opt.post_data)
       meth = "POST";
+    else if (opt.method)
+      if (strcmp(opt.method, "DELETE") == 0)
+        meth = "DELETE";
+  
     /* Use the full path, i.e. one that includes the leading slash and
        the query string.  E.g. if u->path is "foo/bar" and u->query is
        "param=value", full_path will be "/foo/bar?param=value".  */
diff --git a/src/init.c b/src/init.c
index cafd456..f13e2aa 100644
--- a/src/init.c
+++ b/src/init.c
@@ -157,7 +157,7 @@ static const struct {
 #ifdef ENABLE_DEBUG
   { "debug",            &opt.debug,             cmd_boolean },
 #endif
-  { "defaultpage", 	&opt.default_page,      cmd_string},
+  { "defaultpage", 	&opt.default_page,      cmd_string },
   { "deleteafter",      &opt.delete_after,      cmd_boolean },
   { "dirprefix",        &opt.dir_prefix,        cmd_directory },
   { "dirstruct",        NULL,                   cmd_spec_dirstruct },
@@ -210,6 +210,7 @@ static const struct {
   { "logfile",          &opt.lfilename,         cmd_file },
   { "login",            &opt.ftp_user,          cmd_string },/* deprecated*/
   { "maxredirect",      &opt.max_redirect,      cmd_number },
+  { "method",           &opt.method,            cmd_string },
   { "mirror",           NULL,                   cmd_spec_mirror },
   { "netrc",            &opt.netrc,             cmd_boolean },
   { "noclobber",        &opt.noclobber,         cmd_boolean },
@@ -1754,6 +1755,7 @@ cleanup (void)
   xfree_null (opt.user);
   xfree_null (opt.passwd);
   xfree_null (opt.base_href);
+  xfree_null (opt.method);
 
 #endif /* DEBUG_MALLOC */
 }
diff --git a/src/main.c b/src/main.c
index 992f60a..6be0336 100644
--- a/src/main.c
+++ b/src/main.c
@@ -231,6 +231,7 @@ static struct cmdline_option option_data[] =
     { "load-cookies", 0, OPT_VALUE, "loadcookies", -1 },
     { "local-encoding", 0, OPT_VALUE, "localencoding", -1 },
     { "max-redirect", 0, OPT_VALUE, "maxredirect", -1 },
+    { "method", 0, OPT_VALUE, "method", -1 },
     { "mirror", 'm', OPT_BOOLEAN, "mirror", -1 },
     { "no", 'n', OPT__NO, NULL, required_argument },
     { "no-clobber", 0, OPT_BOOLEAN, "noclobber", -1 },
@@ -610,6 +611,8 @@ HTTP options:\n"),
     N_("\
        --post-file=FILE        use the POST method; send contents of FILE.\n"),
     N_("\
+       --method=HTTPMethod     use HTTPMethod (e.g. PUT, DELETE, etc.) Currently only supports DELETE.\n"),
+    N_("\
        --content-disposition   honor the Content-Disposition header when\n\
                                choosing local file names (EXPERIMENTAL).\n"),
     N_("\
diff --git a/src/options.h b/src/options.h
index 44e0a70..1adca97 100644
--- a/src/options.h
+++ b/src/options.h
@@ -228,6 +228,7 @@ struct options
 
   char *post_data;		/* POST query string */
   char *post_file_name;		/* File to post */
+  char *method;                 /* REST Method to use. */
 
   enum {
     restrict_unix,
-- 
1.8.1.5

