this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

pkg/tool/http: restore Do request header/trailer to accept single strings

https://cuelang.org/cl/1221921 added http.Serve,
which supports both requests and response objects with headers.

As part of that review, the type of the headers map was altered
to be just a list of strings, but it seems like http.Do.request
was changed as well, perhaps by accident or a search-and-replace.

This broke users who were setting an http.Do's request header
to a single string value, which worked on v0.15.x but broke on v0.16.0.
Add a test, and revert the backwards incompatible change.

Fixes #4329.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Ie8c4802501861f76ca3aab97e0e97bb60c9aaf3f
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1235490
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+38 -6
+2 -2
pkg/tool/http/http.cue
··· 40 40 41 41 request: { 42 42 body?: bytes | string 43 - header: [string]: [string, ...string] 44 - trailer: [string]: [string, ...string] 43 + header: [string]: string | [...string] 44 + trailer: [string]: string | [...string] 45 45 } 46 46 response: { 47 47 status: string
+32
pkg/tool/http/http_test.go
··· 21 21 "log" 22 22 "net/http" 23 23 "net/http/httptest" 24 + "slices" 24 25 "strings" 25 26 "testing" 26 27 ··· 258 259 } 259 260 } 260 261 }) 262 + } 263 + } 264 + 265 + // TestRequestHeaders verifies that headers specified as either a single string 266 + // or a list of strings are actually sent in the HTTP request. 267 + func TestRequestHeaders(t *testing.T) { 268 + var gotHeaders http.Header 269 + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 270 + gotHeaders = r.Header 271 + w.Write([]byte("ok")) 272 + })) 273 + t.Cleanup(server.Close) 274 + 275 + v := parse(t, "tool/http.Do", fmt.Sprintf(`{ 276 + method: "GET" 277 + url: "%s" 278 + request: header: { 279 + "X-Single": "single-value" 280 + "X-List": ["val-a", "val-b"] 281 + } 282 + }`, server.URL)) 283 + 284 + _, err := (*httpCmd).Run(nil, &task.Context{Obj: v}) 285 + if err != nil { 286 + t.Fatal(err) 287 + } 288 + if got, want := gotHeaders.Get("X-Single"), "single-value"; got != want { 289 + t.Errorf("X-Single: got %q, want %q", got, want) 290 + } 291 + if got, want := gotHeaders.Values("X-List"), []string{"val-a", "val-b"}; !slices.Equal(got, want) { 292 + t.Errorf("X-List: got %v, want %v", got, want) 261 293 } 262 294 } 263 295
+4 -4
pkg/tool/http/pkg.go
··· 30 30 // 31 31 // request: { 32 32 // body?: bytes | string 33 - // header: [string]: [string, ...string] 34 - // trailer: [string]: [string, ...string] 33 + // header: [string]: string | [...string] 34 + // trailer: [string]: string | [...string] 35 35 // } 36 36 // response: { 37 37 // status: string ··· 227 227 } 228 228 request: { 229 229 body?: bytes | string 230 - header: [string]: [string, ...string] 231 - trailer: [string]: [string, ...string] 230 + header: [string]: string | [...string] 231 + trailer: [string]: string | [...string] 232 232 } 233 233 response: { 234 234 status: string