Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support text/plain Media Type in CloudEventJsonInputFormatter #75

Open
mustafacagataytulun opened this issue Oct 30, 2020 · 2 comments
Open

Comments

@mustafacagataytulun
Copy link

I don't know that this could be considered as an issue or not, but I want to ask/suggest it anyway.

We are trying to use cloud events on OpenShift platform. Our problem is the system sends events to our ASP.NET Core application with text/plain Content-Type. We solved this by copying source code of CloudEventJsonInputFormatter to our project, changing its name to CloudEventTextInputFormatter, and changing SupportedMediaTypes to text/plain like this:

SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("text/plain"));

Since the underlying ReadCloudEventAsync method does not make any transformation while reading the request body, it works like a charm. Here is the code for assigning Data field.

cloudEvent.Data = await new StreamReader(httpRequest.Body, Encoding.UTF8).ReadToEndAsync();

What do you think? Could it be integrated into CloudEventJsonInputFormatter? All it needs is the SupportedMediaTypes line I shared above. I could be like this:

SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/json"));
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/cloudevents+json"));
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("text/plain"));
@jskeet
Copy link
Contributor

jskeet commented Feb 12, 2021

Sorry for not looking at this issue before.

It seems to me that if the HTTP request has a content type of text/plain, and doesn't have a ce-specversion header, it shouldn't be recognized as a CloudEvent. Or are you saying that it does have a ce-specversion header? If you could give a sample request, that would really help.

While it's very likely that the CloudEventJsonInputFormatter will be revised before the 2.0 release, I wouldn't expect it to handle requests that don't conform to the CloudEvents spec... and if it's a binary mode event that has a text/plain payload, I suspect you'd need the a CloudEventPlainTextInputFormatter or equivalent... a class that is designed specifically for JSON has no business handling a request that doesn't use JSON, IMO. (We may well make it easier to create a flexible TextInputFormatter so that you can pass in any CloudEventFormatter and go from there - the event formatter design is still somewhat fluid.)

jskeet added a commit to jskeet/sdk-csharp that referenced this issue Jun 3, 2021
This commit moves it to the sample directory for now. There are
elements we'll want to look at more closely before including it
directly in the package, but anyone can easily look at the code and
include it themselves for now, if it suits their needs.

Means that cloudevents#75 doesn't block the v2 release.

Signed-off-by: Jon Skeet <jonskeet@google.com>
jskeet added a commit that referenced this issue Jun 3, 2021
This commit moves it to the sample directory for now. There are
elements we'll want to look at more closely before including it
directly in the package, but anyone can easily look at the code and
include it themselves for now, if it suits their needs.

Means that #75 doesn't block the v2 release.

Signed-off-by: Jon Skeet <jonskeet@google.com>
@jskeet
Copy link
Contributor

jskeet commented Jun 3, 2021

This is now no longer blocking the 2.0 release, as we've moved it into the ASP.NET Core sample. However, that was basically because there's more to do to it than we have time to do right now. We should have a think about what we want it to look like for 2.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants