diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml new file mode 100644 index 0000000..66ad7bd --- /dev/null +++ b/.github/workflows/makefile.yml @@ -0,0 +1,55 @@ +name: build and test + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + # - name: build using makefile + # run: make websocketd + + - name: build websocketd + run: go build + + - name: Archive build artifacts + uses: actions/upload-artifact@v4 + with: + name: websocketd + path: | + websocketd + ./examples/bash/dump-env.sh + + + test: + needs: build + runs-on: ubuntu-latest + + steps: + - name: Download built websocketd + uses: actions/download-artifact@v4 + with: + name: websocketd + + - name: fix permissions + run: chmod +x ./websocketd && chmod +x ./examples/bash/dump-env.sh + + - name: setup client + run: wget https://github.com/vi/websocat/releases/latest/download/websocat.x86_64-unknown-linux-musl && chmod +x websocat.x86_64-unknown-linux-musl + + - name: test + run: | + ./websocketd --port=8080 ./examples/bash/dump-env.sh & + ./websocat.x86_64-unknown-linux-musl -E ws://$(hostname):8080 diff --git a/Makefile b/Makefile index 47f9ee9..f760427 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ # To manually invoke the locally installed Go, use ./go # Go installation config. -GO_VER=1.11.5 +GO_VER=1.22.3 SYSTEM_NAME:=$(shell uname -s | tr '[:upper:]' '[:lower:]') SYSTEM_ARCH:=$(shell uname -m) GO_ARCH:=$(if $(filter x86_64, $(SYSTEM_ARCH)),amd64,386) diff --git a/config.go b/config.go index e6750ad..6f8ed0a 100644 --- a/config.go +++ b/config.go @@ -54,8 +54,8 @@ func parseCommandLine() *Config { var mainConfig Config var config libwebsocketd.Config - flag.Usage = func() {} flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ContinueOnError) + flag.CommandLine.Usage = func() {} // If adding new command line options, also update the help text in help.go. // The flag library's auto-generate help message isn't pretty enough. diff --git a/go.mod b/go.mod index e40afd2..c3592de 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,7 @@ module github.com/joewalnes/websocketd -go 1.15 +go 1.22.3 -require github.com/gorilla/websocket v1.4.0 +require github.com/gorilla/websocket v1.5.2 + +require golang.org/x/net v0.23.0 // indirect diff --git a/go.sum b/go.sum index cf4fbba..7a88eee 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,8 @@ github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= +github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gorilla/websocket v1.5.2 h1:qoW6V1GT3aZxybsbC6oLnailWnB+qTMVwMreOso9XUw= +github.com/gorilla/websocket v1.5.2/go.mod h1:0n9H61RBAcf5/38py2MCYbxzPIY9rOkpvvMT24Rqs30= +golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= +golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= diff --git a/main.go b/main.go index ec09496..636bec0 100644 --- a/main.go +++ b/main.go @@ -94,13 +94,16 @@ func main() { pos := strings.IndexByte(addr, ':') rediraddr := addr[:pos] + ":" + strconv.Itoa(config.RedirPort) // it would be silly to optimize this one redir := &http.Server{Addr: rediraddr, Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - // redirect to same hostname as in request but different port and probably schema uri := "https://" if !config.Ssl { uri = "http://" } - uri += r.Host[:strings.IndexByte(r.Host, ':')] + addr[pos:] + "/" + if cpos := strings.IndexByte(r.Host, ':'); cpos > 0 { + uri += r.Host[:strings.IndexByte(r.Host, ':')] + addr[pos:] + "/" + } else { + uri += r.Host + addr[pos:] + "/" + } http.Redirect(w, r, uri, http.StatusMovedPermanently) })} diff --git a/release/Makefile b/release/Makefile index eb6feee..6049f6b 100644 --- a/release/Makefile +++ b/release/Makefile @@ -21,7 +21,7 @@ LAST_PATCH_VERSION:=$(shell git ls-remote git@github.com:joewalnes/websocketd.gi VERSION_PATCH:=$(or $(LAST_PATCH_VERSION),0) RELEASE_VERSION=$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH) -GO_VERSION=1.15.7 +GO_VERSION=1.22.3 PLATFORMS=linux_amd64 linux_386 linux_arm linux_arm64 darwin_amd64 freebsd_amd64 freebsd_386 windows_386 windows_amd64 openbsd_386 openbsd_amd64 solaris_amd64