func reqInfoHandler(r *http.Request, param map[string]string, reply *web.Reply) { stream := reply.OpenStream() fmt.Fprintf(stream, "Method: %s\n", r.Method) fmt.Fprintf(stream, "Protocol: %s\n", r.Proto) fmt.Fprintf(stream, "Host: %s\n", r.Host) fmt.Fprintf(stream, "RemoteAddr: %s\n", r.RemoteAddr) fmt.Fprintf(stream, "RequestURI: %q\n", r.RequestURI) fmt.Fprintf(stream, "URL: %#v\n", r.URL) fmt.Fprintf(stream, "Body.ContentLength: %d (-1 means unknown)\n", r.ContentLength) fmt.Fprintf(stream, "Close: %v (relevant for HTTP/1 only)\n", r.Close) fmt.Fprintf(stream, "TLS: %#v\n", r.TLS) fmt.Fprintf(stream, "\nHeaders:\n") r.Header.Write(stream) }
func TestService(request *http.Request, param map[string]string, reply *web.Reply) { stream := reply.OpenStream() clientGone := stream.CloseNotify() ticker := time.NewTicker(1 * time.Second) defer ticker.Stop() fmt.Fprintf(stream, "# ~1KB of junk to force browsers to start rendering immediately: \n") io.WriteString(stream, strings.Repeat("# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n", 13)) for { fmt.Fprintf(stream, "%v\n", time.Now()) stream.Flush() select { case <-ticker.C: case <-clientGone: log.Printf("Client %v disconnected from the clock", request.RemoteAddr) return } } }