You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make datacontenttype value check case-insensitive #282
SDK is using case-sensitive checks when formatting CloudEvents to Json based on "datacontenttype" value. MIME types type and subtype are case insensitive according to the spec.
For example, this code snippet throws exception:
System.ArgumentException: 'JsonEventFormatter cannot serialize data of type System.String with content type 'application/JSON''
CloudEvent cloudEvent = new CloudEvent
{
Id = "event-id",
Type = "event-type",
Source = new Uri("https://cloudevents.io/"),
Time = DateTimeOffset.UtcNow,
DataContentType = "application/JSON",
Data = "text"
};
CloudEventFormatter formatter = new JsonEventFormatter();
var httpContent = cloudEvent.ToHttpContent(ContentMode.Structured, formatter);
Could you clarify which spec (ideally with a link to the specific part) you mean? Is this a MIME types spec, or the CloudEvents spec? https://www.rfc-editor.org/rfc/rfc2046.html states that the charset parameter isn't case-sensitive, and that subtype names of image are not case-sensitive, but I don't see anything similar for "application".
All media type values, subtype values, and
parameter names as defined are case-insensitive. However, parameter
values are case-sensitive unless otherwise specified for the specific
parameter.
We may want to take a look at the code ASP.NET uses for header comparisons (ref) here. It's used in ASP.NET to validate Accepts headers and handle the case-sensitivity rules correctly, AFAIK. It also has some capabilities to filter out invalid subtypes like th application/cloudeventsfoobar that is mentioned in this TODO.
We may want to take a look at the code ASP.NET uses for header comparisons (ref) here.
Yes, it's a shame that's not all in System.Net.Http.Headers.MediaTypeHeaderValue :( I suspect we'll need a really careful sweep through the code to find everything. I'll start keeping a log here...
Yes, it's a shame that's not all in System.Net.Http.Headers.MediaTypeHeaderValue :(
Yes, the Microsoft.Net.Headers stuff was specifically optimized for server/web scenarios as opposed to the "general purpose" types in System.Net.Http.Headers. We can get away with doing source-based code sharing to bring in the functionality from Microsoft.Net.Headers for this.
Activity
jskeet commentedon Mar 6, 2024
Could you clarify which spec (ideally with a link to the specific part) you mean? Is this a MIME types spec, or the CloudEvents spec? https://www.rfc-editor.org/rfc/rfc2046.html states that the charset parameter isn't case-sensitive, and that subtype names of image are not case-sensitive, but I don't see anything similar for "application".
batrived commentedon Mar 6, 2024
@jskeet https://www.rfc-editor.org/rfc/rfc2045#section-2
From the above rfc:
All media type values, subtype values, and
parameter names as defined are case-insensitive. However, parameter
values are case-sensitive unless otherwise specified for the specific
parameter.
jskeet commentedon Mar 6, 2024
Thanks, that's helpful. Will look at what's required here - and also raise it with other CE SDK maintainers.
captainsafia commentedon Mar 6, 2024
We may want to take a look at the code ASP.NET uses for header comparisons (ref) here. It's used in ASP.NET to validate
Acceptsheaders and handle the case-sensitivity rules correctly, AFAIK. It also has some capabilities to filter out invalid subtypes like thapplication/cloudeventsfoobarthat is mentioned in this TODO.jskeet commentedon Mar 8, 2024
Yes, it's a shame that's not all in System.Net.Http.Headers.MediaTypeHeaderValue :( I suspect we'll need a really careful sweep through the code to find everything. I'll start keeping a log here...
captainsafia commentedon Mar 8, 2024
Yes, the
Microsoft.Net.Headersstuff was specifically optimized for server/web scenarios as opposed to the "general purpose" types inSystem.Net.Http.Headers. We can get away with doing source-based code sharing to bring in the functionality fromMicrosoft.Net.Headersfor this.