ucp
This commit is contained in:
+17
-4
@@ -23,7 +23,7 @@ func OrderHandler(applier OrderReadApplier) http.Handler {
|
||||
mux.HandleFunc("POST /{id}/fulfillments", s.handleCreateFulfillment)
|
||||
mux.HandleFunc("POST /{id}/returns", s.handleRequestReturn)
|
||||
mux.HandleFunc("POST /{id}/refunds", s.handleIssueRefund)
|
||||
return mux
|
||||
return withUCPAgent(withJSONContentType(mux))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -46,7 +46,7 @@ func CartHandler(applier CartApplier) http.Handler {
|
||||
mux.HandleFunc("GET /{id}", s.handleGetCart)
|
||||
mux.HandleFunc("PUT /{id}", s.handleUpdateCart)
|
||||
mux.HandleFunc("POST /{id}/cancel", s.handleCancelCart)
|
||||
return mux
|
||||
return withUCPAgent(withJSONContentType(mux))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -70,7 +70,7 @@ func CheckoutHandler(applier CheckoutApplier, orderSvc ...OrderApplier) http.Han
|
||||
mux.HandleFunc("PUT /{id}", s.handleUpdateCheckout)
|
||||
mux.HandleFunc("POST /{id}/complete", s.handleCompleteCheckout)
|
||||
mux.HandleFunc("POST /{id}/cancel", s.handleCancelCheckout)
|
||||
return mux
|
||||
return withUCPAgent(withJSONContentType(mux))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -113,5 +113,18 @@ func Handler(cartApplier CartApplier, opts Options) http.Handler {
|
||||
mux.HandleFunc("POST /checkout-sessions/{id}/cancel", checkoutSrv.handleCancelCheckout)
|
||||
}
|
||||
|
||||
return mux
|
||||
return withUCPAgent(withJSONContentType(mux))
|
||||
}
|
||||
|
||||
// withUCPAgent wraps a handler with UCP-Agent header parsing middleware.
|
||||
func withUCPAgent(next http.Handler) http.Handler {
|
||||
return WithUCPAgent(next)
|
||||
}
|
||||
|
||||
// withJSONContentType is a middleware that ensures all responses have Content-Type: application/json.
|
||||
func withJSONContentType(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user