]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl: add %{method} to the -w variables
authorDaniel Stenberg <daniel@haxx.se>
Mon, 13 Jul 2020 07:58:29 +0000 (09:58 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 14 Jul 2020 15:53:45 +0000 (17:53 +0200)
Gets the CURLINFO_EFFECTIVE_METHOD from libcurl.

Added test 1197 to verify.

docs/cmdline-opts/write-out.d
src/tool_writeout.c
src/tool_writeout.h
tests/data/Makefile.inc
tests/data/test1197 [new file with mode: 0644]
tests/data/test970

index 9786a9af48dd0239d8773dda3a3261015f6e2051..686bda6eab4680cf88e62a449a887d5c4847f958 100644 (file)
@@ -60,6 +60,9 @@ either IPv4 or IPv6 (Added in 7.29.0)
 .B local_port
 The local port number of the most recently done connection (Added in 7.29.0)
 .TP
+.B method
+The http method used in the most recent HTTP request (Added in 7.72.0)
+.TP
 .B num_connects
 Number of new connects made in the recent transfer. (Added in 7.12.3)
 .TP
index d8ccbcbda4f5a043e30db4dac59dadf38e5971ff..41441ff30d15960975867f6235e1e7cbad050b57 100644 (file)
@@ -32,6 +32,8 @@
 static const struct writeoutvar variables[] = {
   {"url_effective", VAR_EFFECTIVE_URL, 0,
    CURLINFO_EFFECTIVE_URL, JSON_STRING},
+  {"method", VAR_EFFECTIVE_METHOD, 0,
+   CURLINFO_EFFECTIVE_METHOD, JSON_STRING},
   {"http_code", VAR_HTTP_CODE, 0,
    CURLINFO_RESPONSE_CODE, JSON_LONG},
   {"response_code", VAR_HTTP_CODE, 0,
@@ -142,6 +144,13 @@ void ourWriteOut(CURL *curl, struct OutStruct *outs, const char *writeinfo)
                    && stringp)
                   fputs(stringp, stream);
                 break;
+              case VAR_EFFECTIVE_METHOD:
+                if((CURLE_OK == curl_easy_getinfo(curl,
+                                                  CURLINFO_EFFECTIVE_METHOD,
+                                                  &stringp))
+                   && stringp)
+                  fputs(stringp, stream);
+                break;
               case VAR_HTTP_CODE:
                 if(CURLE_OK ==
                    curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &longinfo))
index a21787ab9aa3be69ecd313820669b44a9df33029..68bacb9d4167fa9cf3a5f092fb241236f1949325 100644 (file)
@@ -39,6 +39,7 @@ typedef enum {
   VAR_HTTP_CODE_PROXY,
   VAR_HEADER_SIZE,
   VAR_REQUEST_SIZE,
+  VAR_EFFECTIVE_METHOD,
   VAR_EFFECTIVE_URL,
   VAR_CONTENT_TYPE,
   VAR_NUM_CONNECTS,
index eaf347d91d18a5c79c3ee445c5e8b21c2ce9bc8e..667d7951a98d4ef140561f0e01a500c6033b8c4c 100644 (file)
@@ -141,7 +141,7 @@ test1168 \
 test1170 test1171 test1172 test1173 test1174 test1175 test1176 test1177 \
 test1178 test1179 \
 \
-test1190 test1191 test1192 test1193 test1194 test1195 test1196 \
+test1190 test1191 test1192 test1193 test1194 test1195 test1196 test1197 \
 \
 test1200 test1201 test1202 test1203 test1204 test1205 test1206 test1207 \
 test1208 test1209 test1210 test1211 test1212 test1213 test1214 test1215 \
diff --git a/tests/data/test1197 b/tests/data/test1197
new file mode 100644 (file)
index 0000000..96d368f
--- /dev/null
@@ -0,0 +1,88 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+followlocation
+--write-out
+</keywords>
+</info>
+
+#
+# Server-side
+<reply>
+<data nocheck="yes">
+HTTP/1.1 302 OK swsbounce swsclose\r
+Date: Thu, 09 Nov 2010 14:49:00 GMT\r
+Content-Length: 8\r
+Connection: close\r
+Content-Type: text/plain\r
+Location: ./11970001\r
+\r
+monster
+</data>
+<data1 nocheck="yes">
+HTTP/1.1 200 OK\r
+Date: Thu, 09 Nov 2010 14:49:00 GMT\r
+Content-Length: 15\r
+Connection: close\r
+Content-Type: text/plain; charset=us-ascii\r
+\r
+bigger monster
+</data1>
+
+</reply>
+
+#
+# Client-side
+<client>
+<server>
+http
+</server>
+ <name>
+HTTP POST redirected to GET and --write-out method
+ </name>
+ <command>
+http://%HOSTIP:%HTTPPORT/1197 -w "%{method}\n" -L -d "twinkle twinkle little star"
+</command>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<strip>
+^User-Agent:.*
+</strip>
+<protocol>
+POST /1197 HTTP/1.1\r
+Host: %HOSTIP:%HTTPPORT\r
+Accept: */*\r
+Content-Length: 27\r
+Content-Type: application/x-www-form-urlencoded\r
+\r
+twinkle twinkle little starGET /11970001 HTTP/1.1\r
+Host: %HOSTIP:%HTTPPORT\r
+Accept: */*\r
+\r
+</protocol>
+
+<stdout>
+HTTP/1.1 302 OK swsbounce swsclose\r
+Date: Thu, 09 Nov 2010 14:49:00 GMT\r
+Content-Length: 8\r
+Connection: close\r
+Content-Type: text/plain\r
+Location: ./11970001\r
+\r
+HTTP/1.1 200 OK\r
+Date: Thu, 09 Nov 2010 14:49:00 GMT\r
+Content-Length: 15\r
+Connection: close\r
+Content-Type: text/plain; charset=us-ascii\r
+\r
+bigger monster
+GET
+</stdout>
+
+</verify>
+</testcase>
index e6d138f49442cc47884d1c0e2d6ba40e97ab5775..c0a88a79821f7c2e499c25f9923cbbae0ad10143 100644 (file)
@@ -61,7 +61,7 @@ Accept: */*
 \r
 </protocol>
 <stdout nonewline="yes">
-{"url_effective":"http://%HOSTIP:%HTTPPORT/970","http_code":200,"response_code":200,"http_connect":0,"time_total":0.000013,"time_namelookup":0.000013,"time_connect":0.000013,"time_appconnect":0.000013,"time_pretransfer":0.000013,"time_starttransfer":0.000013,"size_header":4019,"size_request":4019,"size_download":445,"size_upload":0,"speed_download":13,"speed_upload":13,"content_type":"text/html","num_connects":1,"time_redirect":0.000013,"num_redirects":0,"ssl_verify_result":0,"proxy_ssl_verify_result":0,"filename_effective":"log/out970","remote_ip":"%HOSTIP","remote_port":%HTTPPORT,"local_ip":"127.0.0.1","local_port":13,"http_version":"1.1","scheme":"HTTP","curl_version":"curl-unit-test-fake-version"}
+{"url_effective":"http://%HOSTIP:%HTTPPORT/970","method":"GET","http_code":200,"response_code":200,"http_connect":0,"time_total":0.000013,"time_namelookup":0.000013,"time_connect":0.000013,"time_appconnect":0.000013,"time_pretransfer":0.000013,"time_starttransfer":0.000013,"size_header":4019,"size_request":4019,"size_download":445,"size_upload":0,"speed_download":13,"speed_upload":13,"content_type":"text/html","num_connects":1,"time_redirect":0.000013,"num_redirects":0,"ssl_verify_result":0,"proxy_ssl_verify_result":0,"filename_effective":"log/out970","remote_ip":"%HOSTIP","remote_port":%HTTPPORT,"local_ip":"127.0.0.1","local_port":13,"http_version":"1.1","scheme":"HTTP","curl_version":"curl-unit-test-fake-version"}
 </stdout>
 </verify>
 </testcase>