via

Simple pubsub server inspired by https://patchbay.pub/
git clone https://git.ce9e.org/via.git

commit
662645fa864b50c949101be777a60b0e39182802
parent
947c63f71b306c40ea6ba328401dd88d36985fff
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2025-06-05 08:31
include historyRemaining in body instead of header

In JS, CORS requests have limited access to headers

Diffstat

M README.md 2 +-
M via.go 10 +++++++---

2 files changed, 8 insertions, 4 deletions


diff --git a/README.md b/README.md

@@ -31,7 +31,7 @@ Use the `hmsg` prefix if you want to keep a history:
   31    31 
   32    32 	# the history only keeps up to 100 entries
   33    33 	# you can consolidate it by replacing all entries by a single message
   34    -1 	# the `X-Via-History-Remaining` header on POST tells you how much space is left
   -1    34 	# the `historyRemaining` field in POST responses tells you how much space is left
   35    35 	curl http://localhost:8001/hmsg/someid -d combined -H 'Last-Event-Id: 3' -X PUT
   36    36 
   37    37 You can also protect your ID with a password so no one else can listen to

diff --git a/via.go b/via.go

@@ -225,6 +225,12 @@ func post(w http.ResponseWriter, r *http.Request) {
  225   225 	topic, ok := topics[key]
  226   226 	mux.RUnlock()
  227   227 
   -1   228 	response := make(map[string]int)
   -1   229 	defer func() {
   -1   230 		w.Header().Set("Content-Type", "application/json")
   -1   231 		json.NewEncoder(w).Encode(response)
   -1   232 	}()
   -1   233 
  228   234 	if !ok {
  229   235 		return
  230   236 	}
@@ -236,9 +242,7 @@ func post(w http.ResponseWriter, r *http.Request) {
  236   242 
  237   243 	if topic.hasHistory {
  238   244 		topic.storeHistory(key)
  239    -1 
  240    -1 		remain := maxHistorySize - len(topic.history)
  241    -1 		w.Header().Set("X-Via-History-Remaining", fmt.Sprintf("%d", remain))
   -1   245 		response["historyRemaining"] = maxHistorySize - len(topic.history)
  242   246 	}
  243   247 }
  244   248