feat(runtime): track upstream response headers in logging and usage reporting
- Added APIs to store, retrieve, and clone upstream response headers in context for detailed logging. - Updated `RecordAPIResponseMetadata`, `RecordAPIWebsocketHandshake`, and related methods to capture response headers. - Extended `UsageReporter` to include response headers in published usage records. - Enhanced payload tests to validate response headers' integrity and persistence. - Refactored `usage.Record` to support optional `ResponseHeaders` field.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package helps
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/router-for-me/CLIProxyAPI/v7/internal/config"
|
||||
"github.com/router-for-me/CLIProxyAPI/v7/internal/logging"
|
||||
)
|
||||
|
||||
func TestRecordAPIResponseMetadataStoresHeadersWhenRequestLogDisabled(t *testing.T) {
|
||||
ctx := logging.WithResponseHeadersHolder(context.Background())
|
||||
headers := http.Header{}
|
||||
headers.Add("X-Upstream-Request-Id", "upstream-req-1")
|
||||
|
||||
RecordAPIResponseMetadata(ctx, &config.Config{}, http.StatusOK, headers)
|
||||
headers.Set("X-Upstream-Request-Id", "mutated")
|
||||
|
||||
got := logging.GetResponseHeaders(ctx)
|
||||
if got.Get("X-Upstream-Request-Id") != "upstream-req-1" {
|
||||
t.Fatalf("response header = %q, want %q", got.Get("X-Upstream-Request-Id"), "upstream-req-1")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user