本文整理汇总了Golang中net/http.ResponseWriter.WriteString方法的典型用法代码示例。如果您正苦于以下问题:Golang ResponseWriter.WriteString方法的具体用法?Golang ResponseWriter.WriteString怎么用?Golang ResponseWriter.WriteString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net/http.ResponseWriter
的用法示例。
在下文中一共展示了ResponseWriter.WriteString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: httpProxy
func httpProxy(writer http.ResponseWriter, request *http.Request) {
proxyRequest := new(http.Request)
*proxyRequest = *request
log.Printf("request = %s %s", request.Method, request.URL.Host)
if strings.ToUpper(proxyRequest.Method) == "CONNECT" {
hostPort := request.URL.Host
pandora, err := dialer.Dial("tcp", hostPort) // tuner.pandora.com:443
if err != nil {
log.Printf("pianobarproxy: error: %v", err)
writer.WriteHeader(http.StatusInternalServerError)
return
}
client, writer, err := writer.(http.Hijacker).Hijack()
writer.WriteString("HTTP/1.0 200 Connection Established\r\n\r\n")
writer.Flush()
go pipe(client, pandora)
go pipe(pandora, client)
return
}
proxyRequest.Proto = "HTTP/1.1"
proxyRequest.ProtoMajor = 1
proxyRequest.ProtoMinor = 1
proxyRequest.Close = false
// Remove the connection header to the backend. We want a
// persistent connection, regardless of what the client sent
// to us.
if proxyRequest.Header.Get("Connection") != "" {
proxyRequest.Header = make(http.Header)
copyHeader(proxyRequest.Header, request.Header)
proxyRequest.Header.Del("Connection")
}
response, err := transport.RoundTrip(proxyRequest)
if err != nil {
log.Printf("pianobarproxy: error: %v", err)
writer.WriteHeader(http.StatusInternalServerError)
return
}
copyHeader(writer.Header(), response.Header)
writer.WriteHeader(response.StatusCode)
if response.Body != nil {
io.Copy(io.Writer(writer), response.Body)
}
}