Added streaming

This commit is contained in:
2024-03-22 14:37:21 +01:00
parent 1803bf7108
commit 17158235ea
3 changed files with 46 additions and 0 deletions

View File

@ -52,6 +52,13 @@ func TestRouter(t *testing.T) {
return ctx.File("testdata/file.txt")
})
s.Get("/flush", func(ctx server.Context) error {
ctx.Response().WriteString("Hello 1\n")
ctx.Response().WriteString("Hello 2\n")
ctx.Response().Flush()
return nil
})
s.Get("/echo", func(ctx server.Context) error {
return ctx.Copy(ctx.Request())
})
@ -123,6 +130,7 @@ func TestRouter(t *testing.T) {
{Method: "GET", URL: "/error", Body: "", Status: http.StatusUnauthorized, Response: "Not logged in"},
{Method: "GET", URL: "/error2", Body: "", Status: http.StatusUnauthorized, Response: "Not logged in\nMissing auth token"},
{Method: "GET", URL: "/file", Body: "", Status: http.StatusOK, Response: "Hello File"},
{Method: "GET", URL: "/flush", Body: "", Status: http.StatusOK, Response: "Hello 1\nHello 2\n"},
{Method: "GET", URL: "/not-found", Body: "", Status: http.StatusNotFound, Response: http.StatusText(http.StatusNotFound)},
{Method: "GET", URL: "/request/data", Body: "", Status: http.StatusOK, Response: "GET HTTP/1.1 example.com /request/data"},
{Method: "GET", URL: "/request/header", Body: "", Status: http.StatusOK, Response: ""},