title: Is it possible to force return the Connection header from ASP.NET Core through IIS?
body: <p><em>Note: This is similar to <a href="https://stackoverflow.com/questions/63345613/is-it-possible-to-force-return-the-connection-header-from-asp-net-core-through-a">this question</a> but is about IIS, not Azure App Service on Linux.</em></p>
  <p>I have an API endpoint for uploading large files. The file should not be uploaded if authentication fails, if the filename is invalid, etc. We even accept a checksum and skip upload if the file already exists.</p>
  <p>Unfortunately, Kestrel always drains the entire request body no matter what I do in user code (see <a href="https://github.com/dotnet/aspnetcore/issues/24732" rel="nofollow noreferrer">this issue</a> for details). In other words, the user has to &quot;upload&quot; the whole file before getting the response, even if my code does not read the response body and returns an early error response. In that issue I received a tip that I could return a <code>Connection: close</code> header to avoid that. Unfortunately, while I receive the header in the response when debugging locally, I do not receive it when running in production through IIS. In other words, IIS seems to remove that header if it's present in the ASP.NET Core response.</p>
  <p>Is there any way to force return a <code>Connection: close</code> header through IIS?</p>