Skip to content

Commit 1d375d5

Browse files
distinguish Upgrader.Upgrade from Upgrade
1 parent ea4d1f6 commit 1d375d5

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

doc.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
//
77
// Overview
88
//
9-
// The Conn type represents a WebSocket connection. A server application uses
10-
// the Upgrade function from an Upgrader object with a HTTP request handler
11-
// to get a pointer to a Conn:
9+
// The Conn type represents a WebSocket connection. Within the context of an
10+
// HTTP request handler, a server application calls the Upgrade method of an
11+
// Upgrader instance obtaining a pointer to a Conn:
1212
//
1313
// var upgrader = websocket.Upgrader{
1414
// ReadBufferSize: 1024,
@@ -147,9 +147,15 @@
147147
// CheckOrigin: func(r *http.Request) bool { return true },
148148
// }
149149
//
150-
// The deprecated Upgrade function does not enforce an origin policy. It's the
151-
// application's responsibility to check the Origin header before calling
152-
// Upgrade.
150+
// We recommend the upgrader.Upgrade method to perform an upgrade
151+
// from an HTTP connection to a websocket connection. This method performs
152+
// origin policy checking using the CheckOrigin field associated with the
153+
// Upgrader instance.
154+
//
155+
// By contrast, the deprecated package-level Upgrade function
156+
// does not perform origin checking. In this case is the application's
157+
// responsibility to manually check the Origin header before calling the
158+
// package-level Upgrade function.
153159
//
154160
// Compression EXPERIMENTAL
155161
//

server.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,14 @@ func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeade
228228
return c, nil
229229
}
230230

231-
// Upgrade upgrades the HTTP server connection to the WebSocket protocol.
231+
// DEPRECATED - use websocket.Upgrader instead.
232232
//
233-
// This function is deprecated, use websocket.Upgrader instead.
233+
// Upgrade upgrades the HTTP server connection to the WebSocket protocol.
234234
//
235-
// The application is responsible for checking the request origin before
236-
// calling Upgrade. An example implementation of the same origin policy is:
235+
// Note that the application is responsible for checking the request origin
236+
// before calling Upgrade. This is not done automatically as with the use of the
237+
// Upgrader.Upgrade method. An example implementation of the same origin policy
238+
// check is:
237239
//
238240
// if req.Header.Get("Origin") != "http://"+req.Host {
239241
// http.Error(w, "Origin not allowed", 403)

0 commit comments

Comments
 (0)