Skip to content

Commit 8eb7080

Browse files
committed
Improve error message when request body size is unknown
Closes #689.
1 parent 6667b36 commit 8eb7080

3 files changed

Lines changed: 7 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818

1919
### Changed
2020

21+
- Improved error message when request body size cannot be determined to suggest
22+
setting `Content-Length` explicitly or using chunked `Transfer-Encoding` (#560)
2123
- **BREAKING** `Connection#readpartial` now raises `EOFError` instead of
2224
returning `nil` at end-of-stream, and supports an `outbuf` parameter,
2325
conforming to the `IO#readpartial` API. `Body#readpartial` and

lib/http/request/body.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ def size
5454
elsif @source.nil?
5555
0
5656
else
57-
raise RequestError, "cannot determine size of body: #{@source}"
57+
raise RequestError,
58+
"cannot determine size of body: #{@source.inspect}; " \
59+
"set the Content-Length header explicitly or use chunked Transfer-Encoding"
5860
end
5961
end
6062

test/http/request/body_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@
291291
err = assert_raises(HTTP::RequestError) { subject_under_test.size }
292292
assert_match(/cannot determine size of body/, err.message)
293293
assert_includes err.message, body.inspect
294+
assert_match(/Content-Length/, err.message)
295+
assert_match(/chunked Transfer-Encoding/, err.message)
294296
end
295297
end
296298
end

0 commit comments

Comments
 (0)