Skip to content

Commit fad3cd1

Browse files
fix(client): elide content type header on requests without body
1 parent 27e5a99 commit fad3cd1

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

lib/hubspot_sdk/internal/transport/base_client.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ def initialize(
311311
HubSpotSDK::Internal::Util.deep_merge(*[req[:body], opts[:extra_body]].compact)
312312
end
313313

314+
headers.delete("content-type") if body.nil?
315+
314316
url = HubSpotSDK::Internal::Util.join_parsed_uri(
315317
@base_url_components,
316318
{**req, path: path, query: query}

test/hubspot_sdk/client_test.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ def test_client_redirect_307
312312
assert_equal(recorded.method, _1.method)
313313
assert_equal(recorded.body, _1.body)
314314
assert_equal(
315-
recorded.headers.transform_keys(&:downcase).fetch("content-type"),
316-
_1.headers.transform_keys(&:downcase).fetch("content-type")
315+
recorded.headers.transform_keys(&:downcase)["content-type"],
316+
_1.headers.transform_keys(&:downcase)["content-type"]
317317
)
318318
end
319319
end
@@ -438,8 +438,9 @@ def test_default_headers
438438
)
439439

440440
assert_requested(:any, /./) do |req|
441-
headers = req.headers.transform_keys(&:downcase).fetch_values("accept", "content-type")
442-
headers.each { refute_empty(_1) }
441+
headers = req.headers.transform_keys(&:downcase)
442+
expected = req.body.nil? ? ["accept"] : %w[accept content-type]
443+
headers.fetch_values(*expected).each { refute_empty(_1) }
443444
end
444445
end
445446
end

0 commit comments

Comments
 (0)