Compare commits
2 Commits
d36ef7b629
...
3095d54f99
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3095d54f99 | ||
|
|
d6db4a8a58 |
@@ -122,13 +122,17 @@ type Session struct {
|
||||
}
|
||||
|
||||
func (s *S) injectContext(w http.ResponseWriter, r *http.Request) error {
|
||||
id, err := r.Cookie("uuid")
|
||||
if err != nil || id.Value == "" {
|
||||
return io.EOF
|
||||
id := r.URL.Query().Get("uuid")
|
||||
if id == "" {
|
||||
c, err := r.Cookie("uuid")
|
||||
if err != nil || c.Value == "" {
|
||||
return io.EOF
|
||||
}
|
||||
id = c.Value
|
||||
}
|
||||
ctx := r.Context()
|
||||
ctx = context.WithValue(ctx, "session", Session{
|
||||
ID: id.Value,
|
||||
ID: id,
|
||||
})
|
||||
*r = *r.WithContext(ctx)
|
||||
return nil
|
||||
|
||||
16
cmd/testws/index.html
Normal file
16
cmd/testws/index.html
Normal file
@@ -0,0 +1,16 @@
|
||||
<html>
|
||||
<header>
|
||||
<script>
|
||||
function log(msg) {
|
||||
console.log(msg)
|
||||
}
|
||||
const ws = new Websocket("wss://out-test.breel.dev/ws")
|
||||
ws.onmessage = () => { console.log("got a message") }
|
||||
ws.onerror = () => { console.log("got an error") }
|
||||
ws.onclose = () => { console.log("closed") }
|
||||
</script>
|
||||
</header>
|
||||
<body>
|
||||
<div id="msg"></div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user