dapr / dapr/dotnet-sdk

Expected a supported JSON media type but got "application/octet-stream".

Open
#1,088 3 comments 0 reactions 0 assignees View on GitHub
kind/bug
Dominant language
C#
Stars
1.2k
Forks
378
Avg merge
2d 1h
Merged PRs (30d)
6

Description

## Expected Behavior

When publishing and receiving events through pubsub component using rawPayload=true, receiving subscriber endpoint should be able to deserialize response body into a valid object.

## Actual Behavior

When receiving events from topic subscriber where enableRawPayload=true and message was sent with rawPayload=true with Content-Type of application/json, the receiving end throws an exception from the useCloudEvents middleware.

> Microsoft.AspNetCore.Http.BadHttpRequestException: Expected a supported JSON media type but got "application/octet-stream".
> at Microsoft.AspNetCore.Http.RequestDelegateFactory.Log.UnexpectedJsonContentType(HttpContext httpContext, String contentType, Boolean shouldThrow)
> at Microsoft.AspNetCore.Http.RequestDelegateFactory.g__TryReadBodyAsync|90_0(HttpContext httpContext, Type bodyType, String parameterTypeName, String parameterName, Boolean allowEmptyRequestBody, Boolean throwOnBadRequest)
> at Microsoft.AspNetCore.Http.RequestDelegateFactory.<>c__DisplayClass90_2.<b__2>d.MoveNext()
> --- End of stack trace from previous location ---
> at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
> at Dapr.CloudEventsMiddleware.ProcessBodyAsync(HttpContext httpContext, String charSet)
> at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

Or when the app.UseCloudEvents() middleware is completely removed the source binding binds the data as null. When using streamReader to read the request.Body it is:

> {
> "data_base64": "ew0KICAgICJvcmRlcklkIjogIjMiLA0KICAgICJyZXF1ZXN0SWQiOiAiMSIsDQogICAgImZvb2JhcnMiOiBbDQogICAgICAgIHsNCiAgICAgICAgICAgICJuYW1lIjogIkZvbyIsDQogICAgICAgICAgICAibGFzdG5hbWUiOiAiQmFyIg0KICAgICAgICB9DQogICAgXQ0KfQ\u003d\u003d",
> "datacontenttype": "application/octet-stream",
> "id": "60071be7-1379-45c4-8f3a-fea2202b8b89",
> "pubsubname": "servicebus-pubsub",
> "source": "Dapr",
> "specversion": "1.0",
> "topic": "sbt-foo-bar-topic",
> "type": "com.dapr.event.sent"
> }

## Steps to Reproduce the Problem

Configure startup with app.UseCloudEvents();
Publish messages where rawPayload=true set up a subscriber with enableRawPayload = true.

## Questions

How raw payloads should be deserialized? There is so little information about how to use pubsub without CloudEvents as rawPayload messages, especially for the AspNetCore SDK. I am starting to feel like using ServiceBus SDK to receive messages outside of dapr cluster.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.