cloudevents / cloudevents/sdk-csharp

Support text/plain Media Type in CloudEventJsonInputFormatter

Open
#75 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
334
Forks
88
Avg merge
7m
Merged PRs (30d)
2

Description

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"));

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with CloudEventJsonInputFormatter and its SupportedMediaTypes configuration, then inspect how ReadCloudEventAsync handles the request body. Confirm whether text/plain should be accepted alongside the existing media types and identify the relevant formatter behavior to verify. Done means text/plain requests are supported without the copied formatter workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.