Skip to content

Commit 8c2ddbb

Browse files
fix(client): elide content type header on requests without body
1 parent 2a2a137 commit 8c2ddbb

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

lib/orb/internal/transport/base_client.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ def initialize(
306306
Orb::Internal::Util.deep_merge(*[req[:body], opts[:extra_body]].compact)
307307
end
308308

309+
headers.delete("content-type") if body.nil?
310+
309311
url = Orb::Internal::Util.join_parsed_uri(@base_url_components, {**req, path: path, query: query})
310312
headers, encoded = Orb::Internal::Util.encode_content(headers, body)
311313
{

test/orb/client_test.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ def test_client_redirect_307
208208
assert_equal(recorded.method, _1.method)
209209
assert_equal(recorded.body, _1.body)
210210
assert_equal(
211-
recorded.headers.transform_keys(&:downcase).fetch("content-type"),
212-
_1.headers.transform_keys(&:downcase).fetch("content-type")
211+
recorded.headers.transform_keys(&:downcase)["content-type"],
212+
_1.headers.transform_keys(&:downcase)["content-type"]
213213
)
214214
end
215215
end
@@ -344,8 +344,9 @@ def test_default_headers
344344
orb.customers.create(email: "dev@stainless.com", name: "x")
345345

346346
assert_requested(:any, /./) do |req|
347-
headers = req.headers.transform_keys(&:downcase).fetch_values("accept", "content-type")
348-
headers.each { refute_empty(_1) }
347+
headers = req.headers.transform_keys(&:downcase)
348+
expected = req.body.nil? ? ["accept"] : %w[accept content-type]
349+
headers.fetch_values(*expected).each { refute_empty(_1) }
349350
end
350351
end
351352
end

0 commit comments

Comments
 (0)