Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net Core 2.2 / Kestrel / Swagger disabling Chunking / Encoding

I'm being a REST api in .Net Core 2.2 / Kestrel / Swagger 3 (OpenAPI). I've noticed in Fiddler that my responses are all marked as Encoded with the yellow banner, have Chunked Encoding enabled and the Json is littered with 5J, etc. How can I disable that?

I've seen a few threads on SO, but they are for older versions...

Also, my guess is that I'd like to do this through middleware some how... so I don't have to change any controls and Swagger all plugs in through that.

There was one SO response that linked to a GitHub project that supposedly did it, but the project was deleted.

It comes back like this in Fiddler (with the 51 and the 0):

51
{
  "": [
    "Content-Type must be application/x-www-form-urlencoded."
  ]
}
0

Header:

Transfer-Encoding: chunked
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcR2lsIFJvc2luXERvY3VtZW50c1xWaXN1YWwgU3R1ZGlvIDIwMTdcUHJvamVjdHNcRFRNUzJcdG9rZW4=?=
Server: Kestrel
Content-Type: application/json
like image 259
SledgeHammer Avatar asked Nov 18 '25 10:11

SledgeHammer


1 Answers

The Microsoft.AspNetCore.Buffering package contains a middleware that will buffer your responses. Just call UseResponseBuffering() on your application builder during start up configuration.

Note that your responses still may be chunked by anything that's sitting in front of Kestrel (IIS, nginx, etc.).

As an aside, having your responses chunked shouldn't be causing any problems, unless you have some strange non-conformant HTTP client communicating with it. The HTTP stack of anything hitting your server should be decoding the chunking behind the scenes.

like image 57
Collin Dauphinee Avatar answered Nov 21 '25 00:11

Collin Dauphinee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!