mirror of
https://github.com/AmanTahiliani/box-box.git
synced 2026-08-07 19:56:18 -04:00
fix(#76): preserve pacing and empty-state truth
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user