【curl】 Note: Unnecessary use of -X or --request, POST is already inferred.


❯ curl -X POST "https://httpbin.org/post" -H "accept: application/json"


Note: Unnecessary use of -X or --request, POST is already inferred.

-d や --data があると自動で POST と判断するので -X POST などは不要だって。


❯ echo '{
  "user_id" : 123,
  "name" : "ワロ田",
  "age" : 14
}' | curl -vs -H 'Content-Type: application/json; charset=UTF-8' -H 'Accept: application/json' -d @- https://httpbin.org/post
* Host httpbin.org:443 was resolved.
* IPv6: (none)
* IPv4: 54.152.142.77, 3.224.7.64, 35.172.19.140, 34.238.6.191
*   Trying 54.152.142.77:443...
* Connected to httpbin.org (54.152.142.77) port 443
* ALPN: curl offers h2,http/1.1
* (304) (OUT), TLS handshake, Client hello (1):
*  CAfile: /etc/ssl/cert.pem
*  CApath: none
* (304) (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256 / [blank] / UNDEF
* ALPN: server accepted h2
* Server certificate:
*  subject: CN=httpbin.org
*  start date: Aug 20 00:00:00 2024 GMT
*  expire date: Sep 17 23:59:59 2025 GMT
*  subjectAltName: host "httpbin.org" matched cert's "httpbin.org"
*  issuer: C=US; O=Amazon; CN=Amazon RSA 2048 M02
*  SSL certificate verify ok.
* using HTTP/2
* [HTTP/2] [1] OPENED stream for https://httpbin.org/post
* [HTTP/2] [1] [:method: POST]
* [HTTP/2] [1] [:scheme: https]
* [HTTP/2] [1] [:authority: httpbin.org]
* [HTTP/2] [1] [:path: /post]
* [HTTP/2] [1] [user-agent: curl/8.7.1]
* [HTTP/2] [1] [content-type: application/json; charset=UTF-8]
* [HTTP/2] [1] [accept: application/json]
* [HTTP/2] [1] [content-length: 55]
> POST /post HTTP/2
> Host: httpbin.org
> User-Agent: curl/8.7.1
> Content-Type: application/json; charset=UTF-8
> Accept: application/json
> Content-Length: 55
>
* upload completely sent off: 55 bytes
< HTTP/2 200
< date: Sun, 13 Apr 2025 03:08:32 GMT
< content-type: application/json
< content-length: 557
< server: gunicorn/19.9.0
< access-control-allow-origin: *
< access-control-allow-credentials: true
<
{
  "args": {},
  "data": "{  \"user_id\" : 123,  \"name\" : \"\u30ef\u30ed\u7530\",  \"age\" : 14}",
  "files": {},
  "form": {},
  "headers": {
    "Accept": "application/json",
    "Content-Length": "55",
    "Content-Type": "application/json; charset=UTF-8",
    "Host": "httpbin.org",
    "User-Agent": "curl/8.7.1",
    "X-Amzn-Trace-Id": "Root=1-67fb2ab0-3685bdfa4519f20b0d94c818"
  },
  "json": {
    "age": 14,
    "name": "\u30ef\u30ed\u7530",
    "user_id": 123
  },
  "origin": "114.123.123.8",
  "url": "https://httpbin.org/post"
}
* Connection #0 to host httpbin.org left intact


❯ echo '{
  "user_id" : 123,
  "name" : "ワロ田",
  "age" : 14
}' | curl -s -H 'Content-Type: application/json; charset=UTF-8' -H 'Accept: application/json' -d @- https://httpbin.org/post | jq
{
  "args": {},
  "data": "{  \"user_id\" : 123,  \"name\" : \"ワロ田\",  \"age\" : 14}",
  "files": {},
  "form": {},
  "headers": {
    "Accept": "application/json",
    "Content-Length": "55",
    "Content-Type": "application/json; charset=UTF-8",
    "Host": "httpbin.org",
    "User-Agent": "curl/8.7.1",
    "X-Amzn-Trace-Id": "Root=1-67fb2b2f-6faa217ece89a13acc5315"
  },
  "json": {
    "age": 14,
    "name": "ワロ田",
    "user_id": 123
  },
  "origin": "114.123.123.81",
  "url": "https://httpbin.org/post"
}

Form からの POST があるので

リクエストヘッダは2つつけたほうが

「JSON の POST ですよ」

とはっきり明示できそうです。

 

🧑🏻‍💻 参考



負荷ベンチマークツール wrk てシンプルで良いなあ

👉 WordPress で cf-cache-status: BYPASS のままで HIT にならない

シンプルで使いやすい感じ。


❯ wrk -v
wrk 4.2.0 [kqueue] Copyright (C) 2012 Will Glozer
Usage: wrk <options> <url>
  Options:
    -c, --connections <N>  Connections to keep open
    -d, --duration    <T>  Duration of test
    -t, --threads     <N>  Number of threads to use

    -s, --script      <S>  Load Lua script file
    -H, --header      <H>  Add header to request
        --latency          Print latency statistics
        --timeout     <T>  Socket/request timeout
    -v, --version          Print version details

  Numeric arguments may include a SI unit (1k, 1M, 1G)
  Time arguments may include a time unit (2s, 2m, 2h)


❯ wrk https://android.benigumo.com
Running 10s test @ https://android.benigumo.com
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   237.81ms  226.51ms   1.77s    88.62%
    Req/Sec    27.29     15.51    70.00     61.59%
  480 requests in 10.05s, 47.63MB read
  Socket errors: connect 0, read 0, write 0, timeout 2
Requests/sec:     47.77
Transfer/sec:      4.74MB

Lua とか合わせて使えるらしいので便利だろうと思えます。

👉 wg/wrk: Modern HTTP benchmarking tool


WordPress で cf-cache-status: BYPASS のままで HIT にならない

私の場合だけども、cloudflare で。


❯ curl -sI https://android.benigumo.com/ | grep 'cf-cache'
cf-cache-status: BYPASS

どうやっても「HIT」にならない。

レスポンスヘッダーに set-cookie があると cloudflare のキャッシュが効かなくなるらしい。

Additionally, the following headers have given me grief with CF in the past, they should not be present:

Set-Cookie

👉 CF-CACHE-STATUS showing BYPASS - Website, Application, Performance - Cloudflare Community

確認すると、謎の cookie セットがある。


❯ curl -sI https://android.benigumo.com/
HTTP/2 200
date: Sun, 02 Feb 2025 06:42:13 GMT
content-type: text/html; charset=UTF-8
vary: Accept-Encoding
vary: accept, content-type
set-cookie: 6666cd76f96956469e7be39d750cc7d9=1738478533; expires=Sun, 02-Feb-2025 07:42:13 GMT; Max-Age=3600; path=/

web リソース内を grep して、

あやしそうなプラグインを特定後、無効化しながら確認する。

私の場合は、中華産プラグインでした。

削除後。


❯ curl -sI https://android.benigumo.com/ | grep 'cf-cache'
cf-cache-status: HIT

1秒あたり15リクエストしか返せなかったのが、

キャシュが効いて71リクエストを返せるようになりました!


❯ wrk https://android.benigumo.com
Running 10s test @ https://android.benigumo.com
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   201.93ms  252.04ms   1.57s    88.06%
    Req/Sec    38.47     20.07    90.00     63.01%
  713 requests in 10.03s, 68.66MB read
  Socket errors: connect 0, read 0, write 0, timeout 1
Requests/sec:     71.06
Transfer/sec:      6.84MB

Cloudfrare プラグインは有料化への誘導なだけなので、

記事の更新や追加時のキャッシュのパージは手動で行います。