Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions api/pkg/apis/v1alpha1/vendors/margo/device-agent-vendor.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,15 +751,13 @@ func (self *DeviceAgentVendor) downloadBundle(request v1alpha2.COARequest) v1alp
"Serving bundle for device %s with verified digest %s (%d bytes)",
deviceClientId, actualDigest, len(bundleData))

// Set headers directly in fasthttp context
setFastHTTPResponseHeaders(request.Context, "application/vnd.margo.bundle.v1+tar+gzip", actualDigest)

// Return with proper headers
return createSuccessResponseWithHeaders(span,
"application/vnd.margo.bundle.v1+tar+gzip",
map[string]string{
"Content-Type": "application/vnd.margo.bundle.v1+tar+gzip",
"Cache-Control": "public, max-age=31536000, immutable",
"ETag": fmt.Sprintf("\"%s\"", actualDigest), // Quoted ETag
"Vary": "Accept-Encoding",
},
nil,
v1alpha2.OK,
&bundleData,
)
Expand Down Expand Up @@ -900,15 +898,13 @@ func (self *DeviceAgentVendor) downloadDeployment(request v1alpha2.COARequest) v
"Serving deployment %s with verified digest %s (%d bytes)",
deploymentId, actualDigest, len(yamlContent))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't modify createSuccessResponseWithHeaders at all. Just set headers directly on fasthttp and don't pass metadata:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


// Set headers directly in fasthttp context
setFastHTTPResponseHeaders(request.Context, "application/yaml", actualDigest)

// Return with proper headers
return createSuccessResponseWithHeaders(span,
"application/yaml",
map[string]string{
"Content-Type": "application/yaml",
"Cache-Control": "public, max-age=31536000, immutable",
"ETag": fmt.Sprintf("\"%s\"", actualDigest), // Quoted ETag
"Vary": "Accept-Encoding",
},
nil,
v1alpha2.OK,
&yamlContent,
)
Expand Down
21 changes: 21 additions & 0 deletions api/pkg/apis/v1alpha1/vendors/margo/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/eclipse-symphony/symphony/coa/pkg/logger"
"github.com/valyala/fasthttp"
"gopkg.in/yaml.v2"

"github.com/eclipse-symphony/symphony/coa/pkg/apis/v1alpha2"
Expand All @@ -15,6 +16,8 @@ import (
"go.opentelemetry.io/otel/trace"
)

var helperVendorLogger = logger.NewLogger("coa.runtime")

// Helper method for error responses
func createErrorResponse(logger logger.Logger, span trace.Span, err error, message string, errorType v1alpha2.State) v1alpha2.COAResponse {
logger.InfofCtx(context.Background(), "err: %s, msg: %s", err.Error(), message)
Expand Down Expand Up @@ -322,3 +325,21 @@ func createSuccessResponseWithHeadersSimple[T any](

return observ_utils.CloseSpanWithCOAResponse(span, coaResponse), nil
}

// setFastHTTPResponseHeaders sets standard cache and artifact headers (ETag, Cache-Control, Content-Type) directly on FastHTTP context
func setFastHTTPResponseHeaders(
ctx context.Context,
contentType string,
digest string,
) {
if fhCtx, ok := ctx.Value(v1alpha2.COAFastHTTPContextKey).(*fasthttp.RequestCtx); ok {
fhCtx.Response.Header.Set("Content-Type", contentType)
fhCtx.Response.Header.Set("Cache-Control", "public, max-age=31536000, immutable")
fhCtx.Response.Header.Set("ETag", fmt.Sprintf("\"%s\"", digest)) // Quoted ETag per spec
fhCtx.Response.Header.Set("Vary", "Accept-Encoding")

helperVendorLogger.InfofCtx(ctx, "Set response headers directly - ETag: %s", digest)
} else {
helperVendorLogger.WarnfCtx(ctx, "Could not access fasthttp context to set headers")
}
}