From: Russ Cox Date: Wed, 24 Aug 2011 02:39:25 +0000 (-0400) Subject: http: delete error kludge X-Git-Tag: weekly.2011-09-01~109 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=03582b33086c60d09c28e20a6dcdc0dcdd9074c7;p=gostls13.git http: delete error kludge The kludge is targeted at broken web browsers like Chrome and IE, but it gets in the way of sending 400 or 500-series error results with formatted bodies in response to AJAX requests made by pages executing in those browsers. Now the AJAX cases will work and Chrome and IE will be as broken with Go servers as they are with all the other servers. Fixes #2169. R=bradfitz, dsymonds CC=golang-dev https://golang.org/cl/4930047 --- diff --git a/src/pkg/http/server.go b/src/pkg/http/server.go index b8eb716c09..cf15b5f470 100644 --- a/src/pkg/http/server.go +++ b/src/pkg/http/server.go @@ -491,55 +491,6 @@ func (w *response) Write(data []byte) (n int, err os.Error) { return m + n, err } -// If this is an error reply (4xx or 5xx) -// and the handler wrote some data explaining the error, -// some browsers (i.e., Chrome, Internet Explorer) -// will show their own error instead unless the error is -// long enough. The minimum lengths used in those -// browsers are in the 256-512 range. -// Pad to 1024 bytes. -func errorKludge(w *response) { - const min = 1024 - - // Is this an error? - if kind := w.status / 100; kind != 4 && kind != 5 { - return - } - - // Did the handler supply any info? Enough? - if w.written == 0 || w.written >= min { - return - } - - // Is it a broken browser? - var msg string - switch agent := w.req.UserAgent(); { - case strings.Contains(agent, "MSIE"): - msg = "Internet Explorer" - case strings.Contains(agent, "Chrome/"): - msg = "Chrome" - default: - return - } - msg += " would ignore this error page if this text weren't here.\n" - - // Is it text? ("Content-Type" is always in the map) - baseType := strings.SplitN(w.header.Get("Content-Type"), ";", 2)[0] - switch baseType { - case "text/html": - io.WriteString(w, "") - case "text/plain": - io.WriteString(w, "\n") - for w.written < min { - io.WriteString(w, msg) - } - } -} - func (w *response) finishRequest() { // If this was an HTTP/1.0 request with keep-alive and we sent a Content-Length // back, we can make this a keep-alive response ... @@ -555,7 +506,6 @@ func (w *response) finishRequest() { if w.needSniff { w.sniff() } - errorKludge(w) if w.chunking { io.WriteString(w.conn.buf, "0\r\n") // trailer key/value pairs, followed by blank line