Skip to content

Commit d441b4a

Browse files
authored
fix: handle header null values (#92)
1 parent fdcca66 commit d441b4a

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

lib/resend/mailer.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ def get_headers(mail)
9292
params
9393
end
9494

95+
# Remove nils from header values
96+
def cleanup_headers(headers)
97+
headers.delete_if { |_k, v| v.nil? }
98+
end
99+
95100
# Gets the values of the headers that are set through the `#mail` method
96101
#
97102
# @param Mail mail Rails Mail object
@@ -101,6 +106,7 @@ def mail_headers_values(mail)
101106
mail[:headers].unparsed_value.each do |k, v|
102107
params[k.to_s] = v
103108
end
109+
cleanup_headers(params)
104110
params
105111
end
106112

@@ -113,8 +119,7 @@ def headers_values(mail)
113119
unignored_headers(mail).each do |h|
114120
params[h.name.to_s] = h.unparsed_value
115121
end
116-
# remove nil header values
117-
params.delete_if { |_k, v| v.nil? }
122+
cleanup_headers(params)
118123
params
119124
end
120125

lib/resend/request.rb

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def perform
3535
}
3636

3737
options[:body] = @body.to_json unless @body.empty?
38+
3839
resp = HTTParty.send(@verb.to_sym, "#{BASE_URL}#{@path}", options)
3940

4041
check_json!(resp)

lib/resend/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Resend
4-
VERSION = "0.17.1"
4+
VERSION = "0.17.2"
55
end

spec/railtie/mailer_spec.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ def with_overwritten_headers(to, subject)
5454

5555
def with_nil_header_values(to, subject)
5656
headers["X-Entity-Ref-ID"] = nil
57-
mail(to: to, subject: subject) do |format|
57+
mail(to: to, subject: subject, headers: {
58+
"custom-header1": nil,
59+
"custom-header2": "v2"
60+
}) do |format|
5861
format.text { render plain: "txt" }
5962
format.html { render html: "<p>html</p>".html_safe }
6063
end
@@ -157,6 +160,6 @@ class TestMailerWithDisplayName < TestMailer
157160
it "#build_resend_params handles nil values" do
158161
message = TestMailer.with_nil_header_values("[email protected]", "Test!")
159162
body = @mailer.build_resend_params(message)
160-
expect(body[:headers]).to be nil
163+
expect(body[:headers].keys).to eq(["custom-header2"])
161164
end
162165
end

0 commit comments

Comments
 (0)