Browse Source

fixed websocket not being handled correctly

master
forest 2 months ago
parent
commit
323a46cd00
6 changed files with 20 additions and 4 deletions
  1. +1
    -1
      README.md
  2. +0
    -0
      build.sh
  3. +3
    -0
      cachingproxy/Dockerfile
  4. +1
    -1
      cachingproxy/build-docker.sh
  5. +15
    -2
      cachingproxy/main.go
  6. +0
    -0
      run.sh

+ 1
- 1
README.md View File

@ -21,7 +21,7 @@ which runs on my laptop (`192.168.0.46` is my laptop's IP address on my home net
```
stream:
image: sequentialread/owncast-caching-proxy:0.0.12
image: sequentialread/owncast-caching-proxy:0.0.15
command: 192.168.0.46:8080
volumes:
- /dockerdata/owncast-caching-proxy/cache:/app/cache


+ 0
- 0
build.sh View File


+ 3
- 0
cachingproxy/Dockerfile View File

@ -4,8 +4,11 @@
RUN mkdir /build
WORKDIR /build
RUN apk add --update --no-cache ca-certificates git \
&& go get github.com/koding/websocketproxy
COPY . .
RUN go build -v $GO_BUILD_ARGS -o /build/owncast-caching-proxy main.go
FROM alpine
WORKDIR /app
# COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/


+ 1
- 1
cachingproxy/build-docker.sh View File

@ -1,5 +1,5 @@
#!/bin/bash -e
VERSION="0.0.13"
VERSION="0.0.15"
rm -rf dockerbuild || true
mkdir dockerbuild
cp Dockerfile dockerbuild/Dockerfile-amd64


+ 15
- 2
cachingproxy/main.go View File

@ -14,6 +14,8 @@ import (
"strings"
"sync"
"time"
"github.com/koding/websocketproxy"
)
type CachedResponse struct {
@ -41,6 +43,12 @@ func main() {
memCacheHeader := map[string]CachedResponse{}
debugString := strings.ToLower(os.ExpandEnv("$DEBUG"))
debug := debugString == "true" || debugString == "t" || debugString == "1"
websocketURL := &url.URL{
Scheme: "ws",
Host: backend,
Path: "/entry",
}
websocketProxyInstance := websocketproxy.NewProxy(websocketURL)
err = os.MkdirAll("./cache", 0660)
if err != nil {
@ -142,11 +150,16 @@ func main() {
return
}
isWebsocket := strings.HasPrefix(request.URL.Path, "/entry")
if isWebsocket {
websocketProxyInstance.ServeHTTP(writer, request)
return
}
isAPI := strings.HasPrefix(request.URL.Path, "/api")
isConfigJson := strings.HasPrefix(request.URL.Path, "/api/config")
isStream := strings.HasPrefix(request.URL.Path, "/hls")
isWebsocket := strings.HasPrefix(request.URL.Path, "/entry")
isDynamic := !isConfigJson && (isAPI || isStream || isWebsocket)
isDynamic := !isConfigJson && (isAPI || isStream)
if isDynamic {
response, responseBytes, err := proxyRequest(writer, request)


+ 0
- 0
run.sh View File


Loading…
Cancel
Save