MCPcopy Index your code
hub / github.com/coder/websocket / Example_crossOrigin

Function Example_crossOrigin

example_test.go:120–136  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

118}
119
120func Example_crossOrigin() {
121 // This handler demonstrates how to safely accept cross origin WebSockets
122 // from the origin example.com.
123 fn := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
124 c, err := websocket.Accept(w, r, &websocket.AcceptOptions{
125 OriginPatterns: []string{"example.com"},
126 })
127 if err != nil {
128 log.Println(err)
129 return
130 }
131 c.Close(websocket.StatusNormalClosure, "cross origin WebSocket accepted")
132 })
133
134 err := http.ListenAndServe("localhost:8080", fn)
135 log.Fatal(err)
136}
137
138func ExampleConn_Ping() {
139 // Dials a server and pings it 5 times.

Callers

nothing calls this directly

Calls 2

AcceptFunction · 0.92
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…