Failing websocket proxy test case.
$(1) go run wsecho.golistens on :8080$(2) caddy- open http://localhost:2015
- note 404 response to websocket request
Failing websocket proxy test case.
$(1) go run wsecho.go listens on :8080$(2) caddy| localhost | |
| log access.log | |
| proxy /echo 127.0.0.1:8080 { | |
| websocket | |
| } |
| <!doctype html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"/> | |
| </head> | |
| <body> | |
| <script> | |
| function testEchoSocket(path) { | |
| var s = new WebSocket('ws://'+location.hostname+':'+location.port + path); | |
| s.onmessage = function (event) { | |
| console.log(event.data); | |
| } | |
| s.onopen = function (event) { | |
| s.send("ohai"); | |
| } | |
| } | |
| testEchoSocket('/echo'); | |
| </script> | |
| </body> | |
| </html> |
| package main | |
| import ( | |
| "fmt" | |
| "io" | |
| "net/http" | |
| "golang.org/x/net/websocket" | |
| ) | |
| func echoHandler(ws *websocket.Conn) { | |
| fmt.Println("echoHandler") | |
| io.Copy(ws, ws) | |
| } | |
| func main() { | |
| http.Handle("/echo", websocket.Handler(echoHandler)) | |
| http.HandleFunc("/", rootHandler) | |
| err := http.ListenAndServe(":8080", nil) | |
| if err != nil { | |
| panic("ListenAndServe: " + err.Error()) | |
| } | |
| } | |
| func errorHandler(w http.ResponseWriter, r *http.Request, status int) { | |
| w.WriteHeader(status) | |
| fmt.Println(status, r.URL.Path) | |
| } | |
| func rootHandler(w http.ResponseWriter, r *http.Request) { | |
| errorHandler(w, r, http.StatusNotFound) | |
| return | |
| } |