0

Spring boot 2.2, using curl --http2 with default netty as server, for any method with data body, the server responses 413 To Large Entity, even when body is simply {"A":"B"}. While I tried it without body, it works fine. Is this a bug?

$ curl --http2 -X POST -v http://172.27.12.61:8889/a \
>   -H 'content-type: application/json' \
>   -d '{
>   "A": "B"
> }
> '
Note: Unnecessary use of -X or --request, POST is already inferred.
* timeout on name lookup is not supported
*   Trying 172.27.12.61...
* TCP_NODELAY set
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to 172.27.12.61 (172.27.12.61) port 8889 (#0)
> POST /a HTTP/1.1
> Host: 172.27.12.61:8889
> User-Agent: curl/7.51.0
> Accept: */*
> Connection: Upgrade, HTTP2-Settings
> Upgrade: h2c
> HTTP2-Settings: AAMAAABkAAQAAP__
> content-type: application/json
> Content-Length: 15
>
} [15 bytes data]
* upload completely sent off: 15 out of 15 bytes
< HTTP/1.1 413 Request Entity Too Large
< content-length: 0
<
* Curl_http_done: called premature == 0
100    15    0     0  100    15      0    483 --:--:-- --:--:-- --:--:--   483
* Connection #0 to host 172.27.12.61 left intact
Tiina
  • 4,285
  • 7
  • 44
  • 73

1 Answers1

0

Because you specified a http scheme (and not https), and asked curl to use HTTP/2, then curl will attempt to perform a HTTP/1.1 upgrade to HTTP/2, as can be seen from the logs.

Typical HTTP/1.1 upgrades are performed using GET, not POST, notably the HTTP/1.1 upgrade to WebSocket.

The server does not seem to be prepared to accept a POST with a body as an attempt to upgrade and replies with 413 because it does not expect a body.

If you try a GET without body it will likely succeed.

Alternatively, if you know that port 8889 accepts prior-knowledge clear-text HTTP/2 (that is, you can send directly HTTP/2 bytes to that port without having to perform a HTTP/1.1 upgrade), you can try:

curl --http2-prior-knowledge -X POST http://172.27.12.61:8889/a ...

If you use the https scheme, the HTTP/2 protocol will be negotiated via ALPN, and no HTTP/1.1 upgrade will take place, likely succeeding your POST request.

sbordet
  • 16,856
  • 1
  • 50
  • 45