| // Copyright 2012 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. |
| http.HandleFunc("/hijack", func(w http.ResponseWriter, r *http.Request) { |
| hj, ok := w.(http.Hijacker) |
| http.Error(w, "webserver doesn't support hijacking", http.StatusInternalServerError) |
| conn, bufrw, err := hj.Hijack() |
| http.Error(w, err.Error(), http.StatusInternalServerError) |
| // Don't forget to close the connection: |
| bufrw.WriteString("Now we're speaking raw TCP. Say hi: ") |
| s, err := bufrw.ReadString('\n') |
| log.Printf("error reading string: %v", err) |
| fmt.Fprintf(bufrw, "You said: %q\nBye.\n", s) |
| res, err := http.Get("http://www.google.com/robots.txt") |
| robots, err := ioutil.ReadAll(res.Body) |