MCPcopy
hub / github.com/gofiber/fiber / Test_Response_Headers

Function Test_Response_Headers

client/response_test.go:205–241  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

203}
204
205func Test_Response_Headers(t *testing.T) {
206 t.Parallel()
207
208 server := startTestServer(t, func(app *fiber.App) {
209 app.Get("/", func(c fiber.Ctx) error {
210 c.Response().Header.Add("foo", "bar")
211 c.Response().Header.Add("foo", "bar2")
212 c.Response().Header.Add("foo2", "bar")
213
214 return c.SendString("hello world")
215 })
216 })
217 defer server.stop()
218
219 client := New().SetDial(server.dial())
220
221 resp, err := AcquireRequest().
222 SetClient(client).
223 Get("http://example.com")
224
225 require.NoError(t, err)
226
227 headers := make(map[string][]string)
228 for k, v := range resp.Headers() {
229 headers[k] = append(headers[k], v...)
230 }
231
232 require.Equal(t, "hello world", resp.String())
233
234 require.Contains(t, headers["Foo"], "bar")
235 require.Contains(t, headers["Foo"], "bar2")
236 require.Contains(t, headers["Foo2"], "bar")
237
238 require.Len(t, headers, 5) // Foo + Foo2 + Date + Content-Length + Content-Type
239
240 resp.Close()
241}
242
243func Benchmark_Headers(b *testing.B) {
244 server := startTestServer(

Callers

nothing calls this directly

Calls 15

startTestServerFunction · 0.85
AcquireRequestFunction · 0.85
stopMethod · 0.80
dialMethod · 0.80
SetClientMethod · 0.80
ContainsMethod · 0.80
NewFunction · 0.70
GetMethod · 0.65
AddMethod · 0.65
ResponseMethod · 0.65
SendStringMethod · 0.65
SetDialMethod · 0.65

Tested by

no test coverage detected