fix(#76): preserve pacing and empty-state truth

This commit is contained in:
2026-07-12 21:01:42 -04:00
parent c0d1cf2892
commit a0ff8fa5a7
9 changed files with 176 additions and 30 deletions

View File

@@ -2,8 +2,6 @@ package web
import (
"net/http"
"github.com/AmanTahiliani/box-box/internal/api"
)
const (
@@ -11,13 +9,17 @@ const (
dataFreshnessHeader = "X-BoxBox-Data-Freshness"
)
type staleResponseReporter interface {
LastResponseWasStale() bool
}
// markOpenF1Response publishes request-scoped success provenance. Callers must
// pass the scoped client used for this response, never Server.client.
func markOpenF1Response(w http.ResponseWriter, client *api.OpenF1Client) {
func markOpenF1Response(w http.ResponseWriter, client staleResponseReporter) {
markOpenF1AggregateResponse(w, client, false)
}
func markOpenF1AggregateResponse(w http.ResponseWriter, client *api.OpenF1Client, partial bool) {
func markOpenF1AggregateResponse(w http.ResponseWriter, client staleResponseReporter, partial bool) {
freshness := "fresh"
if partial {
freshness = "partial"
@@ -25,7 +27,7 @@ func markOpenF1AggregateResponse(w http.ResponseWriter, client *api.OpenF1Client
markOpenF1Availability(w, client, freshness)
}
func markOpenF1Availability(w http.ResponseWriter, client *api.OpenF1Client, freshness string) {
func markOpenF1Availability(w http.ResponseWriter, client staleResponseReporter, freshness string) {
w.Header().Set(dataSourceHeader, "openf1")
if client != nil && client.LastResponseWasStale() {
w.Header().Set(dataFreshnessHeader, "stale")
@@ -51,7 +53,7 @@ func markLocalResponse(w http.ResponseWriter, partial bool) {
w.Header().Set(dataFreshnessHeader, "local")
}
func markMixedResponse(w http.ResponseWriter, client *api.OpenF1Client, partial bool) {
func markMixedResponse(w http.ResponseWriter, client staleResponseReporter, partial bool) {
w.Header().Set(dataSourceHeader, "mixed")
if client != nil && client.LastResponseWasStale() {
w.Header().Set(dataFreshnessHeader, "stale")