Skip to content

Commit 9ecca0a

Browse files
committed
Add test for post with explicit content-length header.
1 parent 84e2e35 commit 9ecca0a

File tree

1 file changed

+36
-0
lines changed
  • test/async/http/faraday/adapter

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# frozen_string_literal: true
2+
3+
# Released under the MIT License.
4+
# Copyright, 2024-2025, by Samuel Williams.
5+
6+
require "async/http/faraday"
7+
8+
require "sus/fixtures/async/reactor_context"
9+
require "sus/fixtures/async/http/server_context"
10+
11+
describe Async::HTTP::Faraday::Adapter do
12+
with "a local http server" do
13+
include Sus::Fixtures::Async::ReactorContext
14+
include Sus::Fixtures::Async::HTTP::ServerContext
15+
16+
let(:app) do
17+
Protocol::HTTP::Middleware.for do |request|
18+
Protocol::HTTP::Response[200, {}, request.body]
19+
end
20+
end
21+
22+
with "explicit content-length" do
23+
it "client can post resource" do
24+
adapter = Faraday.new(bound_url) do |builder|
25+
builder.adapter :async_http
26+
end
27+
28+
# We test for this case, because Faraday used to add `content-length` header automatically, causing duplicate headers. The adapter explicitly handles this case now, extracting `content-length` from the request headers and passing it into the body wrapper.
29+
response = adapter.post("/index", "Hello World", {"content-type" => "text/plain", "content-length" => "11"})
30+
expect(response.body).to be == "Hello World"
31+
ensure
32+
adapter&.close
33+
end
34+
end
35+
end
36+
end

0 commit comments

Comments
 (0)