Test_HTTPHandler_Flush() — fiber Function Reference
Architecture documentation for the Test_HTTPHandler_Flush() function in adaptor_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD ce8ee17d_c54e_46e1_592a_1f9f421eab8c["Test_HTTPHandler_Flush()"] 8ec96b38_44b4_af66_6f6f_dd60f87b680c["adaptor_test.go"] ce8ee17d_c54e_46e1_592a_1f9f421eab8c -->|defined in| 8ec96b38_44b4_af66_6f6f_dd60f87b680c 1fb74a15_ad44_9be8_6f0d_226181223e63["setFiberContextValueMiddleware()"] ce8ee17d_c54e_46e1_592a_1f9f421eab8c -->|calls| 1fb74a15_ad44_9be8_6f0d_226181223e63 style ce8ee17d_c54e_46e1_592a_1f9f421eab8c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
middleware/adaptor/adaptor_test.go lines 118–206
func Test_HTTPHandler_Flush(t *testing.T) {
t.Parallel()
expectedMethod := fiber.MethodPost
expectedProto := "HTTP/1.1"
expectedProtoMajor := 1
expectedProtoMinor := 1
expectedContentLength := len(expectedBody)
expectedHeader := map[string]string{
"Foo-Bar": "baz",
"Abc": "defg",
"XXX-Remote-Addr": "123.43.4543.345",
}
expectedURL, err := url.ParseRequestURI(expectedRequestURI)
require.NoError(t, err)
type contextKeyType string
expectedContextKey := contextKeyType("contextKey")
expectedContextValue := "contextValue"
callsCount := 0
nethttpH := func(w http.ResponseWriter, r *http.Request) {
callsCount++
assert.Equal(t, expectedMethod, r.Method, "Method")
assert.Equal(t, expectedProto, r.Proto, "Proto")
assert.Equal(t, expectedProtoMajor, r.ProtoMajor, "ProtoMajor")
assert.Equal(t, expectedProtoMinor, r.ProtoMinor, "ProtoMinor")
assert.Equal(t, expectedRequestURI, r.RequestURI, "RequestURI")
assert.Equal(t, expectedContentLength, int(r.ContentLength), "ContentLength")
assert.Empty(t, r.TransferEncoding, "TransferEncoding")
assert.Equal(t, expectedHost, r.Host, "Host")
assert.Equal(t, expectedRemoteAddr, r.RemoteAddr, "RemoteAddr")
body, readErr := io.ReadAll(r.Body)
assert.NoError(t, readErr)
assert.Equal(t, expectedBody, string(body), "Body")
assert.Equal(t, expectedURL, r.URL, "URL")
assert.Equal(t, expectedContextValue, r.Context().Value(expectedContextKey), "Context")
for k, expectedV := range expectedHeader {
v := r.Header.Get(k)
assert.Equal(t, expectedV, v, "Header")
}
w.Header().Set("Header1", "value1")
w.Header().Set("Header2", "value2")
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "request body is ")
flusher, ok := w.(http.Flusher)
if !ok {
t.Fatal("w does not implement http.Flusher")
}
flusher.Flush()
fmt.Fprintf(w, "%q", body)
}
fiberH := HTTPHandlerFunc(http.HandlerFunc(nethttpH))
fiberH = setFiberContextValueMiddleware(fiberH, expectedContextKey, expectedContextValue)
var fctx fasthttp.RequestCtx
var req fasthttp.Request
req.Header.SetMethod(expectedMethod)
req.SetRequestURI(expectedRequestURI)
req.Header.SetHost(expectedHost)
req.BodyWriter().Write([]byte(expectedBody)) //nolint:errcheck // not needed
for k, v := range expectedHeader {
req.Header.Set(k, v)
}
remoteAddr, err := net.ResolveTCPAddr("tcp", expectedRemoteAddr)
require.NoError(t, err)
fctx.Init(&req, remoteAddr, &disableLogger{})
app := fiber.New()
ctx := app.AcquireCtx(&fctx)
defer app.ReleaseCtx(ctx)
err = fiberH(ctx)
require.NoError(t, err)
require.Equal(t, 1, callsCount, "callsCount")
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does Test_HTTPHandler_Flush() do?
Test_HTTPHandler_Flush() is a function in the fiber codebase, defined in middleware/adaptor/adaptor_test.go.
Where is Test_HTTPHandler_Flush() defined?
Test_HTTPHandler_Flush() is defined in middleware/adaptor/adaptor_test.go at line 118.
What does Test_HTTPHandler_Flush() call?
Test_HTTPHandler_Flush() calls 1 function(s): setFiberContextValueMiddleware.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free