MCPcopy
hub / github.com/labstack/echo / TestRequestLogger_allFields

Function TestRequestLogger_allFields

middleware/request_logger_test.go:380–467  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

378}
379
380func TestRequestLogger_allFields(t *testing.T) {
381 e := echo.New()
382
383 isFirstNowCall := true
384 var expect RequestLoggerValues
385 mw := RequestLoggerWithConfig(RequestLoggerConfig{
386 LogValuesFunc: func(c *echo.Context, values RequestLoggerValues) error {
387 expect = values
388 return nil
389 },
390 LogLatency: true,
391 LogProtocol: true,
392 LogRemoteIP: true,
393 LogHost: true,
394 LogMethod: true,
395 LogURI: true,
396 LogURIPath: true,
397 LogRoutePath: true,
398 LogRequestID: true,
399 LogReferer: true,
400 LogUserAgent: true,
401 LogStatus: true,
402 LogContentLength: true,
403 LogResponseSize: true,
404 LogHeaders: []string{"accept-encoding", "User-Agent"},
405 LogQueryParams: []string{"lang", "checked"},
406 LogFormValues: []string{"csrf", "multiple"},
407 timeNow: func() time.Time {
408 if isFirstNowCall {
409 isFirstNowCall = false
410 return time.Unix(1631045377, 0)
411 }
412 return time.Unix(1631045377+10, 0)
413 },
414 })(func(c *echo.Context) error {
415 c.Request().Header.Set(echo.HeaderXRequestID, "123")
416 c.FormValue("to force parse form")
417 return c.String(http.StatusTeapot, "OK")
418 })
419
420 f := make(url.Values)
421 f.Set("csrf", "token")
422 f.Set("multiple", "1")
423 f.Add("multiple", "2")
424 reader := strings.NewReader(f.Encode())
425 req := httptest.NewRequest(http.MethodPost, "/test?lang=en&checked=1&checked=2", reader)
426 req.Header.Set("Referer", "https://echo.labstack.com/")
427 req.Header.Set("User-Agent", "curl/7.68.0")
428 req.Header.Set(echo.HeaderContentLength, strconv.Itoa(int(reader.Size())))
429 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationForm)
430 req.Header.Set(echo.HeaderXRealIP, "8.8.8.8")
431
432 rec := httptest.NewRecorder()
433 c := e.NewContext(req, rec)
434
435 c.SetPath("/test*")
436
437 err := mw(c)

Callers

nothing calls this directly

Calls 8

RequestMethod · 0.95
FormValueMethod · 0.95
StringMethod · 0.95
SetPathMethod · 0.95
RequestLoggerWithConfigFunction · 0.85
SetMethod · 0.80
NewContextMethod · 0.80
AddMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…