![]() private void HandleContentEncoding(HttpContext context) I've replaced my header setting code with following method. I was saved by HttpResponse.OnStarting which allows for interacting with the response just before sending the headers. Simply checking if the header is already present didn't work because Response Compression Middleware sets it upon first attempt to write. I couldn't change how Response Compression Middleware works so I had to be smarter when setting the header. The response is coming compressed but the browser treats it as not compressed. Unfortunately, the fact that header is present twice confuses the browser. The reason for this is that Response Compression Middleware is also blindly using IHeaderDictionary.Append. The response contains two Content-Encoding headers. I've re-enabled it and run the test again. Maintaining compatibility with Response Compression MiddlewareĪs the middleware is now setting the Content-Encoding it could somehow interfere with Response Compression Middleware. Now I had to make sure that I haven't broken anything else. Running the demo application without Response Compression Middleware and behind IIS has confirmed that the solution was working. If ( = Constants.SSE_CONTENT_TYPE)Ĭ("Content-Encoding", "identity") Public async Task Invoke(HttpContext context) ![]() I've added the code for setting the header to the middleware. ![]() One of valid values for Content-Encoding is identity which indicates no compression/modification, it might be enough to prevent IIS from adding compression. The general conclusion from materials that I've found was that IIS will compress the response if it doesn't detect the Content-Encoding header. I wanted to avoid that so I've started researching for other solution. This would certainly work but I would have to put the details into documentation and leave it as a trap for others using the same deployment scenario. The first obvious option was changing the IIS configuration. Preventing IIS from compressing the response That was it, without IIS in front everything was working as expected which meant that IIS (serving as reverse proxy) was compressing the response on its own which resulted in delayed delivery of events. The only external component I was able to identify was IIS Express, so I quickly changed the launch drop down option to run on Kestrel only. It was, so it must have been something external to my application. That really baffled me so I've double checked that the Response Compression Middleware was removed. To my surprise the first thing I've noticed is that the response was still gziped. I went deeper and analyzed DeflateStream also without finding anything specific.Īt this point I've decided to change approach and use Fiddler to see what was happening on the wire. I've gone through the source code of BodyWrapperStream and found nothing. My first thought was that Response Compression Middleware must be writing to the response stream differently then my code (when Response Compression Middleware is present it wraps the original response stream). The difference between working and not working scenario was presence of Response Compression Middleware which I've added while working on previous issue. ![]() Luckily the reporter was extremely helpful in diagnosing the issue and devoted some time to find the difference between his and mine code. The demo application was working correctly while the one on which the person who reported the issue was working didn't. ![]() Initially there was no hint at what are the conditions required for issue to manifest itself. The latest one was about events being delivered with delay (in general one behind) under specific conditions. My Server-Sent Events Middleware seems to be a mine of interesting issues. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |