]> Cypherpunks repositories - gostls13.git/commitdiff
http: delete error kludge
authorRuss Cox <rsc@golang.org>
Wed, 24 Aug 2011 02:39:25 +0000 (22:39 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 24 Aug 2011 02:39:25 +0000 (22:39 -0400)
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

src/pkg/http/server.go

index b8eb716c09ff4644caf1389dfa8ef79f4bffac6a..cf15b5f4704fb6ba0d257ca6d2b380f3c3533a2c 100644 (file)
@@ -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, "<!-- ")
-               for w.written < min {
-                       io.WriteString(w, msg)
-               }
-               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