dockerimg: remove configurability from open browser request
Innie is untrusted, so we can't let it provide a url to open (duh).
There's a chicken-and-egg problem here: we need to start the git
server before launching the container, but we need the container
port information to store the ps1URL on the git server.
Solve it with a little sync/atomic. There's a logical race here,
but if we lose the race, the behavior is that nothing happens,
at which point the user tries again and it works.
Good enough for now.
Co-Authored-By: sketch <hello@sketch.dev>
diff --git a/dockerimg/githttp.go b/dockerimg/githttp.go
index 6270838..7ce5f40 100644
--- a/dockerimg/githttp.go
+++ b/dockerimg/githttp.go
@@ -3,7 +3,6 @@
import (
"crypto/subtle"
"fmt"
- "io"
"log/slog"
"net/http"
"net/http/cgi"
@@ -15,7 +14,7 @@
type gitHTTP struct {
gitRepoRoot string
pass []byte
- browserC chan string // browser launch requests
+ browserC chan bool // browser launch requests
}
func (g *gitHTTP) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@@ -54,20 +53,11 @@
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
- body, err := io.ReadAll(r.Body)
- if err != nil {
- http.Error(w, "Failed to read request body: "+err.Error(), http.StatusBadRequest)
- return
- }
defer r.Body.Close()
- url := strings.TrimSpace(string(body))
- if len(url) == 0 {
- http.Error(w, "URL cannot be empty", http.StatusBadRequest)
- return
- }
+
select {
- case g.browserC <- string(url):
- slog.InfoContext(r.Context(), "open browser", "url", url)
+ case g.browserC <- true:
+ slog.InfoContext(r.Context(), "open browser requested")
w.WriteHeader(http.StatusOK)
default:
http.Error(w, "Too many browser launch requests", http.StatusTooManyRequests)