index90
2020-01-19 17:26:23 +08:00
#6 的代码不对,send header 应该在 send body 之前。
http.HandleFunc("", func(writer http.ResponseWriter, request *http.Request) {
var reader io.Reader
//{
// file, err := os.Open("")
// if err != nil {
// writer.WriteHeader( http.StatusNotFound)
// return
// }
// reader = file
// defer file.Close()
//}
{
resp, err := http.Client{}.Get("")
if err != nil {
writer.WriteHeader( http.StatusNotFound)
return
}
reader = resp.Body
}
writer.Header().Set("content-type", "text/plain")
_, _ = io.Copy(writer, reader)
return
})