I have a Go server that reverse proxies requests to an Apache/PHP server. I have been able to rarely observe that on occasion, the Apache/PHP server will cause Go to produce the following error message: malformed HTTP response "false"
. The requests are identical, and I can sit and refresh a page in a browser which follows that request path, and have the error happen maybe one in a hundred times. I haven't been able to observe any pattern as to when it will happen or not. There is nothing in any access log, error log, or system log that seems relevant.
I have been able to make Go produce that error message with the below code, so it looks like Apache must be sending invalid responses, writing the string "false" directly to a TCP connection.
Any clues to this would be greatly appreciated.
Request:
package main
import (
"fmt"
"net/http"
"net/http/httputil"
)
func main() {
req, _ := http.NewRequest("GET", "http://127.0.0.1:36302", nil)
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
respDump, _ := httputil.DumpResponse(resp, true)
fmt.Println(string(respDump))
}
Server:
package main
import (
"fmt"
"io"
"net"
"time"
)
func main() {
l, _ := net.ListenTCP("tcp4", &net.TCPAddr{net.ParseIP("127.0.0.1"), 36302, ""})
for {
fmt.Println("Accepting connections")
c, err := l.AcceptTCP()
if err != nil {
fmt.Println(err)
}
time.Sleep(1 * time.Second)
io.WriteString(c, "false")
time.Sleep(1 * time.Second)
c.Close()
}
}
tcpdump
?