(t *testing.T)
| 274 | } |
| 275 | |
| 276 | func TestGzipWithMinLengthChunked(t *testing.T) { |
| 277 | e := echo.New() |
| 278 | |
| 279 | // Gzip chunked |
| 280 | chunkBuf := make([]byte, 5) |
| 281 | |
| 282 | req := httptest.NewRequest(http.MethodGet, "/", nil) |
| 283 | req.Header.Set(echo.HeaderAcceptEncoding, gzipScheme) |
| 284 | rec := httptest.NewRecorder() |
| 285 | |
| 286 | var r *gzip.Reader = nil |
| 287 | |
| 288 | c := e.NewContext(req, rec) |
| 289 | next := func(c *echo.Context) error { |
| 290 | rc := http.NewResponseController(c.Response()) |
| 291 | c.Response().Header().Set("Content-Type", "text/event-stream") |
| 292 | c.Response().Header().Set("Transfer-Encoding", "chunked") |
| 293 | |
| 294 | // Write and flush the first part of the data |
| 295 | c.Response().Write([]byte("test\n")) |
| 296 | rc.Flush() |
| 297 | |
| 298 | // Read the first part of the data |
| 299 | assert.True(t, rec.Flushed) |
| 300 | assert.Equal(t, gzipScheme, rec.Header().Get(echo.HeaderContentEncoding)) |
| 301 | |
| 302 | var err error |
| 303 | r, err = gzip.NewReader(rec.Body) |
| 304 | assert.NoError(t, err) |
| 305 | |
| 306 | _, err = io.ReadFull(r, chunkBuf) |
| 307 | assert.NoError(t, err) |
| 308 | assert.Equal(t, "test\n", string(chunkBuf)) |
| 309 | |
| 310 | // Write and flush the second part of the data |
| 311 | c.Response().Write([]byte("test\n")) |
| 312 | rc.Flush() |
| 313 | |
| 314 | _, err = io.ReadFull(r, chunkBuf) |
| 315 | assert.NoError(t, err) |
| 316 | assert.Equal(t, "test\n", string(chunkBuf)) |
| 317 | |
| 318 | // Write the final part of the data and return |
| 319 | c.Response().Write([]byte("test")) |
| 320 | return nil |
| 321 | } |
| 322 | err := GzipWithConfig(GzipConfig{MinLength: 10})(next)(c) |
| 323 | |
| 324 | assert.NoError(t, err) |
| 325 | assert.NotNil(t, r) |
| 326 | |
| 327 | buf := new(bytes.Buffer) |
| 328 | |
| 329 | buf.ReadFrom(r) |
| 330 | assert.Equal(t, "test", buf.String()) |
| 331 | |
| 332 | r.Close() |
| 333 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…