title: How-to drop extra data based on "Content-Length" header in nginx
body: <p>I have a custom application deployed on an IIS instance, which among other things acts as an http file server. For various reasons (bugs), many files are corrupted, in the sense that they have an additional byte at the end of the binary content. Fortunately I've got the exact content length of each file saved on a db, and when my application returns the file, it sets the content-length header correctly (both for corrupted and correct files).</p>
  <p>So I have situations where the content-length in the response header says 100, while the bytes actually present in the body of the same response are 101 (100+1).</p>
  <p>For some internal reason I cannot change the behavior of the application.</p>
  <p>Calling the application directly from the browser (so direct call to IIS) there seem to be no obvious problems, but this situation seems to mess up my nginx (version 1.15.7) behind which the application is exposed in production. Note that the file is served, but it results corrupted (they are Excel files), while those downloaded from direct call to IIS result correct.</p>
  <p>I think there is some problem on some internal buffer because it's like it always discards the last 8192 bytes and in the error log it shows this warning: <code>upstream sent more data than specified in &quot;Content-Length&quot; header while reading response header from upstream</code>.
  I tried to add the directive <code>proxy_buffering: off;</code> but the result does not change (only the warning disappears from the error log).</p>
  <p>My question is: is there any way to trim the response body based on the content-length value provided by my upstream? Obviously if and only if this value is present in the headers.</p>
  <p>Thanks,
  AleBer</p>