Skip to content

Commit

Permalink
re-structured the mock service to upgrade connection earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
ShourieG committed Jul 17, 2024
1 parent b16068b commit 69fddcd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/websocket/_dev/deploy/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
version: "2.3"
services:
websocket-mock-service:
image: golang:1.20-alpine
image: golang:1.21-alpine
hostname: websocket
working_dir: /app
volumes:
- ./websocket-mock-service:/app
ports:
- "80:80"
- "3000:3000"
command: ["go", "run", "main.go"]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module websocket-mock-service

go 1.20
go 1.21.3

require github.com/gorilla/websocket v1.5.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,20 @@ import (

func main() {
http.HandleFunc("/", handleWebSocket)
log.Fatal(http.ListenAndServe(":80", nil))
log.Fatal(http.ListenAndServe(":3000", nil))
}

func handleWebSocket(w http.ResponseWriter, r *http.Request) {
upgrader := websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool { return true },
}
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
log.Println(err)
return
}
defer conn.Close()

if r.URL.Path == "/testbasicauth" {
// Check if the 'Authorization' header is set for basic authentication
authHeader := r.Header.Get("Authorization")
Expand All @@ -28,16 +38,6 @@ func handleWebSocket(w http.ResponseWriter, r *http.Request) {
}
}

upgrader := websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool { return true },
}
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
log.Println(err)
return
}
defer conn.Close()

var responseMessage []map[string]string

if r.URL.Path == "/testbasicauth" {
Expand Down

0 comments on commit 69fddcd

Please # to comment.