本文整理匯總了Golang中http.ResponseWriter.UsingTLS方法的典型用法代碼示例。如果您正苦於以下問題:Golang ResponseWriter.UsingTLS方法的具體用法?Golang ResponseWriter.UsingTLS怎麽用?Golang ResponseWriter.UsingTLS使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類http.ResponseWriter
的用法示例。
在下文中一共展示了ResponseWriter.UsingTLS方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ServeHTTP
// ServeHTTP implements the http.Handler interface for a Web Socket.
func (f Draft75Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
if req.Method != "GET" || req.Proto != "HTTP/1.1" {
w.WriteHeader(http.StatusBadRequest)
io.WriteString(w, "Unexpected request")
return
}
if req.Header["Upgrade"] != "WebSocket" {
w.WriteHeader(http.StatusBadRequest)
io.WriteString(w, "missing Upgrade: WebSocket header")
return
}
if req.Header["Connection"] != "Upgrade" {
w.WriteHeader(http.StatusBadRequest)
io.WriteString(w, "missing Connection: Upgrade header")
return
}
origin, found := req.Header["Origin"]
if !found {
w.WriteHeader(http.StatusBadRequest)
io.WriteString(w, "missing Origin header")
return
}
rwc, buf, err := w.Hijack()
if err != nil {
panic("Hijack failed: " + err.String())
return
}
defer rwc.Close()
var location string
if w.UsingTLS() {
location = "wss://" + req.Host + req.URL.RawPath
} else {
location = "ws://" + req.Host + req.URL.RawPath
}
// TODO(ukai): verify origin,location,protocol.
buf.WriteString("HTTP/1.1 101 Web Socket Protocol Handshake\r\n")
buf.WriteString("Upgrade: WebSocket\r\n")
buf.WriteString("Connection: Upgrade\r\n")
buf.WriteString("WebSocket-Origin: " + origin + "\r\n")
buf.WriteString("WebSocket-Location: " + location + "\r\n")
protocol, found := req.Header["Websocket-Protocol"]
// canonical header key of WebSocket-Protocol.
if found {
buf.WriteString("WebSocket-Protocol: " + protocol + "\r\n")
}
buf.WriteString("\r\n")
if err := buf.Flush(); err != nil {
return
}
ws := newConn(origin, location, protocol, buf, rwc)
f(ws)
}
示例2: ServeHTTP
func (self CBUIReturnVerifier) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
if req.FormValue("signatureVersion") != "2" {
req.Form["CBUI.Error"] = []string{"Invalid CBUI signature version"}
self.Failure.ServeHTTP(rw, req)
self.Logger.Printf("signatureVersion not provided: %v", req.URL.RawQuery)
return
}
myurl := &http.URL{
Host: req.Host,
Path: req.URL.Path,
Scheme: "http",
}
if rw.UsingTLS() {
myurl.Scheme += "s"
}
vurl := &http.URL{
Scheme: self.GatewayURL.Scheme,
Host: self.GatewayURL.Host,
Path: self.GatewayURL.Path,
RawQuery: http.EncodeQuery(map[string][]string{
"UrlEndPoint": []string{myurl.String()},
"HttpParameters": []string{req.URL.RawQuery},
"Action": []string{"VerifySignature"},
"Version": []string{"2008-09-17"},
}),
}
self.Logger.Printf("Verifying signature from %s", self.GatewayURL.String())
resp, _, err := http.Get(vurl.String())
if err != nil {
self.Logger.Printf("Get Failed: %v", err)
req.Form["CBUI.Error"] = []string{err.String()}
self.Failure.ServeHTTP(rw, req)
} else {
xresp := cbuiResponse{}
err = xml.Unmarshal(resp.Body, &xresp)
if err != nil {
req.Form["CBUI.Error"] = []string{err.String()}
self.Failure.ServeHTTP(rw, req)
return
}
if xresp.VerifySignatureResult.VerificationStatus != "Success" {
req.Form["CBUI.Error"] = []string{"Amazon refused signature verification"}
self.Failure.ServeHTTP(rw, req)
return
}
req.Form["CBUI.Ok"] = []string{"true"}
self.Success.ServeHTTP(rw, req)
}
}