<div dir="ltr">The HttpResponse implementation in Mono is located here: <a href="https://github.com/mono/mono/blob/master/mcs/class/System.Web/System.Web/HttpResponse.cs">https://github.com/mono/mono/blob/master/mcs/class/System.Web/System.Web/HttpResponse.cs</a><div>
<br></div><div style>I noticed this piece of code:</div><div style><br></div><div style><pre style="margin-top:0px;margin-bottom:0px;padding:0px;border:0px;font-size:12px;font-family:Consolas,'Liberation Mono',Courier,monospace;color:rgb(51,51,51);line-height:16px">
<div class="" id="LC130" style="margin:0px;padding:0px 0px 0px 10px;border:0px"><span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">if</span> <span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px">worker_request</span> <span class="" style="margin:0px;padding:0px;border:0px">!=</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">null</span><span class="" style="margin:0px;padding:0px;border:0px">)</span></div>
<div class="" id="LC131" style="margin:0px;padding:0px 0px 0px 10px;border:0px">    <span class="" style="margin:0px;padding:0px;border:0px">use_chunked</span> <span class="" style="margin:0px;padding:0px;border:0px">=</span> <span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px">worker_request</span><span class="" style="margin:0px;padding:0px;border:0px">.</span><span class="" style="margin:0px;padding:0px;border:0px">GetHttpVersion</span> <span class="" style="margin:0px;padding:0px;border:0px">()</span> <span class="" style="margin:0px;padding:0px;border:0px">==</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(221,17,68)">"HTTP/1.1"</span><span class="" style="margin:0px;padding:0px;border:0px">);</span></div>
</pre></div><div style><br></div><div style>Which <a href="https://github.com/mono/mono/blob/master/mcs/class/System.Web/System.Web/HttpResponseStream.cs">HttpResponseStream</a> uses to determine whether to chunk the response. Maybe you could try hard-coding that variable to false and see if that fixes your problem? </div>
<div style><br></div><div style>If so, the fix is probably to disable response chunking when FastCGI is being used (not just when the protocol is not HTTP/1.1).</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Fri, Feb 8, 2013 at 2:31 AM, SirNoSkill <span dir="ltr"><<a href="mailto:quandary82@hailmail.net" target="_blank">quandary82@hailmail.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<u></u>




<div><div>Hi,</div>
<div><br> </div>
<div>I've forwarded the error to the nginx mailing list.</div>
<div><br> </div>
<div><a href="http://forum.nginx.org/read.php?2,235985,235988#msg-235988" target="_blank">http://forum.nginx.org/read.php?2,235985,235988#msg-235988</a></div>
<div> </div>
<div>The response I got:</div>
<div>It's bad idea to use "Transfer-Encoding" while working via CGI and</div>
<div>derived protocols like FastCGI. Quote from RFC 3875,</div>
<div><a href="http://tools.ietf.org/html/rfc3875#section-6.3.4" target="_blank">http://tools.ietf.org/html/rfc3875#section-6.3.4</a>:</div>
<div> </div>
<div>The script MUST NOT return any header fields that relate to</div>
<div>client-side communication issues and could affect the server's</div>
<div>ability to send the response to the client.</div>
<div> </div>
<div>As you are talking to nginx via FastCGI, not HTTP, it won't try to</div>
<div>dig into content returned and decode it according to any</div>
<div>Transfer-Encoding. Instead, the "Transfer-Encoding" header</div>
<div>returned will be just dropped by nginx as per RFC 3875.</div><div><div class="h5">
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div>On Sat, Feb 2, 2013, at 09:00 PM, SirNoSkill wrote:</div>
<blockquote type="cite"><div>I have more details on the bug.</div>
<div>The extra bytes that are at the beginning </div>
<pre><code><span>31 </span><span></span><span>39 </span><span></span><span>36 </span><span></span><span>62 </span><span></span><span>36 </span><span></span><span>38 </span><span></span><span>0D </span><span></span><span>0A</span></code></pre>
<div><code><span></span><span></span></code>which reads <span><span><span>196b68/r/n in ASCII</span></span></span></div>
<div><span>196b68 </span>is the filesize of the original image in hex...</div>
<div> </div>
<div>All details + hexdump links added here:</div>
<div><a href="http://stackoverflow.com/questions/14662795/why-do-i-have-unwanted-extra-bytes-at-the-beginning-of-image" target="_blank">http://stackoverflow.com/questions/14662795/why-do-i-have-unwanted-extra-bytes-at-the-beginning-of-image</a></div>

<div> </div>
<div> </div>
<div> </div>
<div>All traffic to that URL [<a href="http://www.daniel-steiger.ch" target="_blank">www.daniel-steiger.ch</a>] (except for the folders /doc and /images), but including images in /Content, is directly forwarded to fastcgi by nginx, as per fastcgi config file for domain.</div>

<div> </div>
<div> </div>
<div> server {</div>
<div>         listen   80;</div>
<div>         server_name <a href="http://www.daniel-steiger.ch" target="_blank">www.daniel-steiger.ch</a> <a href="http://daniel-steiger.ch" target="_blank">daniel-steiger.ch</a>;</div>
<div>         access_log   /var/log/nginx/daniel-steiger.ch.access.log;</div>
<div> </div>
<div>         location / {</div>
<div>                 root /home/danillo/www/HomePage;</div>
<div>                 #index index.html index.htm default.aspx Default.aspx;</div>
<div>                 #fastcgi_index Default.aspx;</div>
<div>                 fastcgi_pass <a href="http://127.0.0.1:9000" target="_blank">127.0.0.1:9000</a>;</div>
<div>                 include /etc/nginx/fastcgi_params;</div>
<div>         }</div>
<div> </div>
<div> </div>
<div><span></span>location /doc {</div>
<div><span></span>root /usr/share;</div>
<div><span></span>autoindex on;</div>
<div><span></span>allow 127.0.0.1;</div>
<div><span></span>deny all;</div>
<div><span></span>}</div>
<div> </div>
<div><span></span>location /images {</div>
<div><span></span>root /usr/share;</div>
<div><span></span>autoindex off;</div>
<div><span></span>}</div>
<div> </div>
<div><span></span>#error_page 404 /404.html;</div>
<div> </div>
<div><span></span># redirect server error pages to the static page /50x.html</div>
<div><span></span>#</div>
<div><span></span>error_page 500 501 503 504 /50x.html;</div>
<div><span></span>location = /50x.html {</div>
<div><span></span>root /home/danillo/www/HomePage;</div>
<div><span></span>}</div>
<div> </div>
<div> </div>
<div><span></span>error_page 502 /502.html;</div>
<div><span></span>location = /502.html {</div>
<div><span></span>root /home/danillo/www/HomePage;</div>
<div><span></span>}</div>
<div> </div>
<div>}</div>
<div> </div>
<div> </div>
<div>It's sufficient to have the file served without FileResult.</div>
<div>Of course it's more efficient if nginx serves it directly, but this is a very low traffic website, so performance is really not my problem ;)</div>
<div> </div>
<div>And by the way, the problem is not finding a workaround.</div>
<div> I have already fixed it with a workaround about a week ago.</div>
<div>I really just want to know where the bug is, because if FileResult malfunctions, there's probably more to it, and I don't want to walk into a subtle not at the first sight spottable bug later, like a botched binary upload/download file.</div>

<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div>On Sat, Feb 2, 2013, at 06:51 AM, Daniel Lo Nigro wrote:</div>
<blockquote type="cite"><div dir="ltr">Hmm... Maybe try an X-Accel-Redirect header instead. This lets Nginx serve the file instead of Mono having to serve it, which makes it more efficient. See if that makes a difference, or if it has the same issue.<div>
 </div>
<div>Why not just link directly to the file, instead of serving it through your C# code?</div>
</div>
<div class="gmail_extra"><div> </div>
<div> </div>
<div class="gmail_quote"><div>On Sun, Feb 3, 2013 at 1:43 AM, quandary82 <span dir="ltr"><<a href="mailto:quandary82@hailmail.net" target="_blank">quandary82@hailmail.net</a>></span> wrote:</div>
<blockquote style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid" class="gmail_quote"><div>Corrected the mime, but seems to be a mono-bug (or fastcgi) anyway.</div>

<div> </div>
<div>
More here:</div>
<div><a href="http://stackoverflow.com/questions/14662795/why-do-i-have-unwanted-extra-bytes-at-the-beginning-of-image" target="_blank">http://stackoverflow.com/questions/14662795/why-do-i-have-unwanted-extra-bytes-at-the-beginning-of-image</a></div>

<div> </div>
<div> </div>
<div> </div>
<div>
--</div>
<div>
View this message in context: <a href="http://mono.1490590.n4.nabble.com/Bug-in-mono-3-0-1-MVC3-File-FileResult-tp4658382p4658422.html" target="_blank">http://mono.1490590.n4.nabble.com/Bug-in-mono-3-0-1-MVC3-File-FileResult-tp4658382p4658422.html</a></div>

<div>

Sent from the Mono - Dev mailing list archive at Nabble.com.</div>
<div><div>_______________________________________________</div>
<div>
Mono-devel-list mailing list</div>
<div><a href="mailto:Mono-devel-list@lists.ximian.com" target="_blank">Mono-devel-list@lists.ximian.com</a></div>
<div><a href="http://lists.ximian.com/mailman/listinfo/mono-devel-list" target="_blank">http://lists.ximian.com/mailman/listinfo/mono-devel-list</a></div>
</div>
</blockquote></div>
</div>
</blockquote><div> </div>
<div>-- </div>
<div>  SirNoSkill</div>
<div>  <a href="mailto:quandary82@hailmail.net" target="_blank">quandary82@hailmail.net</a></div>
<pre>-- 
<a href="http://www.fastmail.fm" target="_blank">http://www.fastmail.fm</a> - mmm... Fastmail...
</pre></blockquote><div> </div>
<div>-- </div>
<div>  SirNoSkill</div>
<div>  <a href="mailto:quandary82@hailmail.net" target="_blank">quandary82@hailmail.net</a></div>
</div></div><span class="HOEnZb"><font color="#888888"><pre>-- 
<a href="http://www.fastmail.fm" target="_blank">http://www.fastmail.fm</a> - IMAP accessible web-mail
</pre>
</font></span></div>

</blockquote></div><br></div>