Skip to content

Commit 678485d

Browse files
dazumaclaude
andcommitted
fix: Use ContentType parser in KafkaBinding#probable_event?
Replace raw string comparison with ContentType parsing so that mixed-case content-type values (e.g. Application/CloudEvents+JSON) are correctly detected as CloudEvents. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Daniel Azuma <dazuma@gmail.com>
1 parent 7848226 commit 678485d

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

lib/cloud_events/kafka_binding.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,10 @@ def register_formatter_methods(formatter,
159159
def probable_event?(message)
160160
headers = message[:headers] || {}
161161
return true if headers.key?("ce_specversion")
162-
content_type = headers["content-type"]
163-
return false unless content_type
164-
content_type.start_with?("application/cloudevents")
162+
content_type_string = headers["content-type"]
163+
return false unless content_type_string
164+
content_type = ContentType.new(content_type_string)
165+
content_type.media_type == "application" && content_type.subtype_base == "cloudevents"
165166
end
166167

167168
##

test/test_kafka_binding.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@
7979
refute kafka_binding.probable_event?(message)
8080
end
8181

82+
it "detects a probable structured event with mixed-case content type" do
83+
message = {
84+
key: nil,
85+
value: "{}",
86+
headers: { "content-type" => "Application/CloudEvents+JSON" },
87+
}
88+
assert kafka_binding.probable_event?(message)
89+
end
90+
8291
it "returns false for a message with no relevant headers" do
8392
message = {
8493
key: nil,

0 commit comments

Comments
 (0)