tatsuhiro-t / spdylay

The experimental SPDY protocol version 2, 3 and 3.1 implementation in C
http://tatsuhiro-t.github.io/spdylay/
MIT License
604 stars 102 forks source link

Add a new spdycat option "--method" to support any arbitrary request method #116

Closed sudheerv closed 10 years ago

sudheerv commented 10 years ago

Add a new spdycat option "--method" to support any arbitrary request method

sudheerv commented 10 years ago

Below is the patch (thanks to Bryan Geffon)

--- src/spdylay_ssl.cc  2014/04/17 20:34:04     818
+++ src/spdylay_ssl.cc  2014/07/09 16:05:36     978
@@ -142,6 +142,7 @@
 int Spdylay::submit_request(const std::string& scheme,
                             const std::string& hostport,
                             const std::string& path,
+                            const std::string& method,
                             const std::map<std::string,std::string>& headers,
                             uint8_t pri,
                             const spdylay_data_provider *data_prd,
@@ -174,7 +175,7 @@
   }

   const char *static_nv[] = {
-    ":method", data_prd ? "POST" : "GET",
+    ":method", method.c_str(),
     ":path", path.c_str(),
     ":version", "HTTP/1.1",
     ":scheme", scheme.c_str(),
--- src/spdylay_ssl.h   2014/04/17 20:34:04     818
+++ src/spdylay_ssl.h   2014/07/09 16:05:36     978
@@ -56,7 +56,7 @@
   bool finish();
   int fd() const;
   int submit_request(const std::string& scheme,
-                     const std::string& hostport, const std::string& path,
+                     const std::string& hostport, const std::string& path, const std::string &method,
                      const std::map<std::string,std::string>& headers,
                      uint8_t pri,
                      const spdylay_data_provider *data_prd,
--- src/spdycat.cc      2014/04/17 20:34:04     818
+++ src/spdycat.cc      2014/07/09 16:05:36     978
@@ -73,6 +73,7 @@
   std::string keyfile;
   std::string datafile;
   std::string proxy_host;
+  std::string method;
   int proxy_port;
   int multiply;
   int spdy_version;
@@ -386,7 +387,7 @@
 {
   std::string path = req->make_reqpath();
   int r = sc.submit_request(get_uri_field(req->uri.c_str(), req->u, UF_SCHEMA),
-                            hostport, path, headers, 3, req->data_prd,
+                            hostport, path, !config.method.empty() ? config.method : (req->data_prd ? "POST" : "GET"), headers, 3, req->data_prd,
                             req->data_length, req, !proxy_host.empty(), proxy_host, proxy_port);
   assert(r == 0);
 }
@@ -956,6 +957,8 @@
       << "                       same with the linking resource will be\n"
       << "                       downloaded.\n"
       << "    -s, --stat         Print statistics.\n"
+      << "    -M, --method=<METHOD>\n"
+      << "                       Use a arbitrary method.\n"
       << "    -H, --header       Add a header to the requests.\n"
       << "    --cert=<CERT>      Use the specified client certificate file.\n"
       << "                       The file must be in PEM format.\n"
@@ -995,6 +998,7 @@
       {"header", required_argument, 0, 'H' },
       {"data", required_argument, 0, 'd' },
       {"multiply", required_argument, 0, 'm' },
+      {"method", required_argument, 0, 'M' },
       {"proxy", required_argument, 0, 'p' },
       {"proxyport", required_argument, 0, 'P' },
       {"cert", required_argument, &flag, 1 },
@@ -1067,6 +1071,10 @@
       config.headers.insert(std::pair<std::string,std::string>(header, value));
       break;
     }
+    case 'M': {
+      config.method = optarg;
+      break;
+    }
     case 'a':
 #ifdef HAVE_LIBXML2
       config.get_assets = true;
tatsuhiro-t commented 10 years ago

Thank you for the patch. Changing request method is already possible using -H option, since in SPDY method is a part of headers:

$ spdycat -nv -H ':method: HEAD' https://nghttp2.org
sudheerv commented 10 years ago

Unfortunately, -H option doesn’t seem to allow modifying headers that start with “:”

$ spdycat -3 -v https://abc.com -H ":method: HEAD” —> this doesn’t work

-H: invalid header: :method: HEAD

$ spdycat -3 -v https://abc.com -H "method: HEAD” —> this works

Thanks,

Sudheer

From: Tatsuhiro Tsujikawa notifications@github.com<mailto:notifications@github.com> Reply-To: tatsuhiro-t/spdylay reply@reply.github.com<mailto:reply@reply.github.com> Date: Thursday, July 10, 2014 at 5:38 AM To: tatsuhiro-t/spdylay spdylay@noreply.github.com<mailto:spdylay@noreply.github.com> Cc: Sudheer Vinukonda sudheerv@yahoo-inc.com<mailto:sudheerv@yahoo-inc.com> Subject: Re: [spdylay] Add a new spdycat option "--method" to support any arbitrary request method (#116)

Thank you for the patch. Changing request method is already possible using -H option, since in SPDY method is a part of headers:

$ spdycat -nv -H ':method: HEAD' https://nghttp2.org

— Reply to this email directly or view it on GitHubhttps://github.com/tatsuhiro-t/spdylay/issues/116#issuecomment-48598606.

tatsuhiro-t commented 10 years ago

I think you are using old version. Could you try latest source code?

sudheerv commented 10 years ago

Ah, I see – great to hear this has been fixed!

Please ignore my patch :)

Sudheer

From: Tatsuhiro Tsujikawa notifications@github.com<mailto:notifications@github.com> Reply-To: tatsuhiro-t/spdylay reply@reply.github.com<mailto:reply@reply.github.com> Date: Thursday, July 10, 2014 at 8:09 AM To: tatsuhiro-t/spdylay spdylay@noreply.github.com<mailto:spdylay@noreply.github.com> Cc: Sudheer Vinukonda sudheerv@yahoo-inc.com<mailto:sudheerv@yahoo-inc.com> Subject: Re: [spdylay] Add a new spdycat option "--method" to support any arbitrary request method (#116)

I think you are using old version. Could you try latest source code?

— Reply to this email directly or view it on GitHubhttps://github.com/tatsuhiro-t/spdylay/issues/116#issuecomment-48617537.

tatsuhiro-t commented 10 years ago

OK. I'll add some note to help message about this usage.

tatsuhiro-t commented 10 years ago

Oh, I have already referred to this usage in -H help message. I completely forgot about it.

sudheerv commented 10 years ago

Thanks - btw, could you tell me if there's a better way to submit patches here? I couldn't find an option to attach files, so, I had to paste the entire patch as a comment, but, I was wondering if there are other easier/convenient options.

tatsuhiro-t commented 10 years ago

Github pull request works, which is easiest and Github documents how to do it. If you don't want to use it, send me a patch formatted by git format-patch command.

sudheerv commented 10 years ago

cool - thanks!