Fix(cuex): send vela/http request headers as the template declares them
Description of your changes
vela/http could not send a request header. http.cue declares request.header and request.trailer as one string per name, but RequestVars decoded them as http.Header, a list per name. CUE refuses a list and the decoder refuses a string, so any call setting a header failed:
json: cannot unmarshal string into Go struct field DoParams.$params.request.header.X-Token of type []string
RequestVarsnow takes one string per name, as the template declares, and thehttp.Headeris built withAdd, so names that differ only in case (X-Tag,x-tag) each keep their value. This matches the workflowvela/httpprovider'sparseHeaders.NewRequest(ctx, RequestVars)is exported, so a provider sending the request through its own client builds it the same way. kubevela's guardedvela/http(component, trait, policy and source templates) moves to it on the bump.
The same commit is already on the new release-1.11 (v1.11.2) and release-1.9 (v1.9.3) branches, cut from the commits kubevela 1.11 and 1.10 pin, so those lines take the fix without moving onto main.
Fixes kubevela/kubevela#7595
How has this code been tested
TestDoSendsRequestHeaders and TestDoSendsCaseVariantHeaders render a template through the real compiler against a local HTTP server; the first fails before the change with the error above, the second with only one of the two values arriving. TestNewRequest covers the exported builder. go test ./cue/... passes (envtest 1.37.0) on main, release-1.11 and release-1.9; golangci-lint clean. kubevela master, release-1.12, 1.11 and 1.10 build and pass ./pkg/cue/... against it.
Behaviour changes in this PR
API change for importers: RequestVars.Request.Header and .Trailer are now map[string]string, not http.Header. Neither form could be set from CUE before, so no template changes. A Go caller building RequestVars by hand passes one string per name, or calls NewRequest instead of setting req.Header itself.
Summary by cubic
Fixes vela/http so request headers and trailers can be sent. The CUE template declares one string per header name, but RequestVars decoded them as http.Header, a list per name, so any template setting a header failed with an unmarshal error and no header arrived.
RequestVars now matches the template (map[string]string), the http.Header is built with Add so names differing only in case each keep their value, and NewRequest is exported so providers sending through their own client build the request the same way. NewRequest keeps the header map usable when a template sets no headers, so a caller adding a header to the result no longer panics. For Go importers, RequestVars.Request.Header and .Trailer are now map[string]string; pass one string per name or use NewRequest instead of setting req.Header directly. The fix is also cut onto release-1.11 (v1.11.2) and release-1.9 (v1.9.3).
Fixes kubevela/kubevela#7595