From 1fddf84f53d75b68180e76b82efface46e377279 Mon Sep 17 00:00:00 2001 From: sgk <sgk@riseup.net> Date: Wed, 2 Apr 2025 11:05:57 +0000 Subject: [PATCH] /pkg/api/{gateway.go,bridge.go} - set header no-store Set Cache-Control header to instruct clients not to cache response --- pkg/api/bridge.go | 6 +++++- pkg/api/gateway.go | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/api/bridge.go b/pkg/api/bridge.go index b5291eb..1c3f030 100644 --- a/pkg/api/bridge.go +++ b/pkg/api/bridge.go @@ -26,6 +26,10 @@ import ( // @Router /api/5/bridges [get] // @Security BucketTokenAuth func (r *registry) ListAllBridges(c echo.Context) error { + + // Set Cache-Control header to instruct clients not to cache response + c.Response().Header().Set("Cache-Control", "no-store") + // Step 1: Validate parameters cc, err := sanitizeCountryCode(c.QueryParam(paramCountryCode)) if err != nil { @@ -63,10 +67,10 @@ func (r *registry) ListAllBridges(c echo.Context) error { // Step 4: sort gateways result, err := sortEndpoints(cc, availableBridges, r.locations, r.lm) - if err != nil { return c.JSON(http.StatusBadRequest, err) } + return c.JSON(http.StatusOK, result) } diff --git a/pkg/api/gateway.go b/pkg/api/gateway.go index 15a3a4b..8454dee 100644 --- a/pkg/api/gateway.go +++ b/pkg/api/gateway.go @@ -32,6 +32,10 @@ var ( // @Router /api/5/gateways [get] // @Security BucketTokenAuth func (r *registry) ListAllGateways(c echo.Context) error { + + // Set Cache-Control header to instruct clients not to cache response + c.Response().Header().Set("Cache-Control", "no-store") + // Step 1: Validate parameters cc, err := sanitizeCountryCode(c.QueryParam(paramCountryCode)) if err != nil { @@ -68,10 +72,10 @@ func (r *registry) ListAllGateways(c echo.Context) error { // Step 4: sort gateways result, err := sortEndpoints(cc, availableGateways, r.locations, r.lm) - if err != nil { return c.JSON(http.StatusBadRequest, nil) } + return c.JSON(http.StatusOK, result) } -- GitLab