<p dir="auto"><strong>What version of Go are you using (go version)?</strong><br>
go version go1.4.2 darwin/amd64</p>
<p dir="auto"><strong>What operating system and processor architecture are you using?</strong><br>
OS X 10.10.3 x86-64</p>
<p dir="auto"><strong>What did you do?</strong><br>
Set <code class="notranslate">w.WriteHeader(http.StatusInternalServerError)</code> prior to calling <code class="notranslate">http.ServeFile</code></p>
<p dir="auto"><strong>What did you expect to see?</strong><br>
A <code class="notranslate">HTTP 500</code> status.</p>
<p dir="auto"><strong>What did you see instead?</strong><br>
A <code class="notranslate">HTTP 200</code> status (and the usual multiple header writes error for messing it up).</p>
<p dir="auto">Currently <code class="notranslate">http.ServeFile</code> (which calls <code class="notranslate">http.ServeContent</code> and then eventually <code class="notranslate">http.serveContent</code>) implicitly sets the status code to HTTP 200 as per <a href="http://golang.org/src/net/http/fs.go#L254" rel="nofollow">this line in src/http/fs.go</a></p>
<p dir="auto">From what I can see, removing this line would result in <code class="notranslate">net/http</code> implicitly calling <code class="notranslate">w.WriteHeader(StatusOK)</code> as per usual (<a href="http://golang.org/src/net/http/server.go#L990" rel="nofollow">http://golang.org/src/net/http/server.go#L990</a>) - which is the behaviour I'd expected until running into this.</p>
<p dir="auto"><strong>Proposed Fix</strong></p>
<ul dir="auto">
<li>Modify <code class="notranslate">http.serveContent</code> to only call <code class="notranslate">w.WriteHeader(code)</code> on an error condition. Set <code class="notranslate">var code int</code> (i.e. zero value) instead of defaulting to <code class="notranslate">code := StatusOK</code>.</li>
<li>If <code class="notranslate">code</code> still has the zero value before we write to the ResponseWriter, then don't call <code class="notranslate">WriteHeader</code>.</li>
<li>This allows the server to either: a) write the header set by the package user or; b) write the implicit <code class="notranslate">http.StatusOK</code> if no header has been set by the time we're ready to write back.</li>
</ul>
<p dir="auto">Writing <code class="notranslate">StatusOK</code> in serveContent appears to be redundant.</p>
<pre class="notranslate">windows-386 just failed with:

<a href="http://build.golang.org/log/3cd6be46a4c7dbe6774fdc891e6417568f4b2b88" rel="nofollow">http://build.golang.org/log/3cd6be46a4c7dbe6774fdc891e6417568f4b2b88</a>

# ..\test
# go run run.go -- fixedbugs/bug015.go
bug015.go:11: missing error "overflow"
FAIL    fixedbugs\bug015.go 0.004s
exit status 1

Which is:

// errorcheck

// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

func main() {
        var i33 int64;
        if i33 == (1&lt;&lt;64) -1 {  // ERROR "overflow"
        }
}


I see no recent change that would've caused that.

Confused.

Also not sure how that could be flaky.</pre>