<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Horray, used mono 3.0.3 stable, and
      "use_chuncked = false;" fixed it.<br>
      Thanks ! ;)<br>
      <br>
      nginx defines this fastcgi parameter: <br>
      fastcgi_param    GATEWAY_INTERFACE    CGI/1.1;<br>
      <br>
      So here a proper patch (tested - works, maybe add
      ordinalignorecase to startswith ?): <br>
/root/sources/mono/3.0.3/mono-3.0.3/mcs/class/System.Web/System.Web/HttpResponse.cs<br>
      starting at line 125:<br>
      <br>
      <br>
              <br>
              internal HttpResponse (HttpWorkerRequest worker_request,
      HttpContext context) : this ()<br>
              {<br>
                  WorkerRequest = worker_request;<br>
                  this.context = context;<br>
      <br>
      #if !TARGET_J2EE<br>
                  if (worker_request != null)<br>
                  {<br>
                      <br>
                      if(worker_request.GetHttpVersion () == "HTTP/1.1")<br>
                      {<br>
                          string GatewayIface =
      context.Request.ServerVariables["GATEWAY_INTERFACE"];<br>
                          use_chunked = (GatewayIface == null ||
      !GatewayIface.StartsWith("CGI"));<br>
                      }<br>
                      else<br>
                          use_chunked = false;<br>
                      <br>
                  }<br>
      #endif<br>
                  writer = new HttpWriter (this);<br>
              }<br>
      <br>
      <br>
      <br>
      Wonderful:<br>
      <a href="http://www.daniel-steiger.ch/TransmitFile.ashx">http://www.daniel-steiger.ch/TransmitFile.ashx</a><br>
      <br>
      Thanks ! ;)<br>
      <br>
      <br>
      <br>
      <br>
      On 02/08/2013 01:15 PM, Daniel Lo Nigro wrote:<br>
    </div>
    <blockquote
cite="mid:CAB1r_+XxpmXv0zmEA54kb3YiFP7SRt0b1-WAjD=WpA8aSxc_Nw@mail.gmail.com"
      type="cite">
      <div dir="ltr">The HttpResponse implementation in Mono is located
        here: <a moz-do-not-send="true"
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 moz-do-not-send="true"
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
              moz-do-not-send="true"
              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">
            <div>
              <div>Hi,</div>
              <div><br>
                 </div>
              <div>I've forwarded the error to the nginx mailing list.</div>
              <div><br>
                 </div>
              <div><a moz-do-not-send="true"
                  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 moz-do-not-send="true"
                  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 moz-do-not-send="true"
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
                        moz-do-not-send="true"
                        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 moz-do-not-send="true"
                        href="http://www.daniel-steiger.ch"
                        target="_blank">www.daniel-steiger.ch</a> <a
                        moz-do-not-send="true"
                        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
                        moz-do-not-send="true"
                        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
                                moz-do-not-send="true"
                                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 moz-do-not-send="true"
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
                                moz-do-not-send="true"
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 moz-do-not-send="true"
                                  href="mailto:Mono-devel-list@lists.ximian.com"
                                  target="_blank">Mono-devel-list@lists.ximian.com</a></div>
                              <div><a moz-do-not-send="true"
                                  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 moz-do-not-send="true"
                        href="mailto:quandary82@hailmail.net"
                        target="_blank">quandary82@hailmail.net</a></div>
                    <pre>-- 
<a moz-do-not-send="true" 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 moz-do-not-send="true"
                      href="mailto:quandary82@hailmail.net"
                      target="_blank">quandary82@hailmail.net</a></div>
                </div>
              </div>
              <span class="HOEnZb"><font color="#888888">
                  <pre>-- 
<a moz-do-not-send="true" href="http://www.fastmail.fm" target="_blank">http://www.fastmail.fm</a> - IMAP accessible web-mail
</pre>
                </font></span></div>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
    <br>
  </body>
</html>