Skip to content

Commit d3a58d5

Browse files
fix(client): elide content type header on requests without body
1 parent a756fca commit d3a58d5

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

lib/lithic/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
Lithic::Internal::Util.deep_merge(*[req[:body], opts[:extra_body]].compact)
307307
end
308308

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

test/lithic/client_test.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ def test_client_redirect_307
213213
assert_equal(recorded.method, _1.method)
214214
assert_equal(recorded.body, _1.body)
215215
assert_equal(
216-
recorded.headers.transform_keys(&:downcase).fetch("content-type"),
217-
_1.headers.transform_keys(&:downcase).fetch("content-type")
216+
recorded.headers.transform_keys(&:downcase)["content-type"],
217+
_1.headers.transform_keys(&:downcase)["content-type"]
218218
)
219219
end
220220
end
@@ -301,8 +301,9 @@ def test_default_headers
301301
lithic.cards.create(type: :VIRTUAL)
302302

303303
assert_requested(:any, /./) do |req|
304-
headers = req.headers.transform_keys(&:downcase).fetch_values("accept", "content-type")
305-
headers.each { refute_empty(_1) }
304+
headers = req.headers.transform_keys(&:downcase)
305+
expected = req.body.nil? ? ["accept"] : %w[accept content-type]
306+
headers.fetch_values(*expected).each { refute_empty(_1) }
306307
end
307308
end
308309
end

0 commit comments

Comments
 (0)