mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-25 17:45:28 +03:00
Added request start time to ServerCtx
This commit is contained in:
@@ -43,10 +43,12 @@ type ServerCtx struct {
|
||||
Request Request
|
||||
Response Response
|
||||
|
||||
// Unique id of the context.
|
||||
// Used by ServerCtx.Logger().
|
||||
// Unique id of the request.
|
||||
ID uint64
|
||||
|
||||
// Start time for the request processing.
|
||||
Time time.Time
|
||||
|
||||
logger ctxLogger
|
||||
s *Server
|
||||
c remoteAddrer
|
||||
@@ -286,6 +288,8 @@ func (s *Server) serveConn(c io.ReadWriter, ctxP **ServerCtx) error {
|
||||
}
|
||||
break
|
||||
}
|
||||
ctx.ID++
|
||||
ctx.Time = time.Now()
|
||||
s.Handler(ctx)
|
||||
shadow := atomic.LoadPointer(&ctx.shadow)
|
||||
if shadow != nil {
|
||||
@@ -308,7 +312,6 @@ func (s *Server) serveConn(c io.ReadWriter, ctxP **ServerCtx) error {
|
||||
break
|
||||
}
|
||||
}
|
||||
ctx.ID++
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
+4
-4
@@ -172,10 +172,10 @@ func TestServerLogger(t *testing.T) {
|
||||
verifyResponse(t, br, 200, "text/html", "requestURI=/foo1, body=\"\", remoteAddr=1.2.3.4:8765")
|
||||
verifyResponse(t, br, 200, "text/html", "requestURI=/foo2, body=\"abcde\", remoteAddr=1.2.3.4:8765")
|
||||
|
||||
expectedLogOut := `#0000000100000000 - 1.2.3.4:8765 - GET http://google.com/foo1 - begin
|
||||
#0000000100000000 - 1.2.3.4:8765 - GET http://google.com/foo1 - end
|
||||
#0000000100000001 - 1.2.3.4:8765 - POST http://aaa.com/foo2 - begin
|
||||
#0000000100000001 - 1.2.3.4:8765 - POST http://aaa.com/foo2 - end
|
||||
expectedLogOut := `#0000000100000001 - 1.2.3.4:8765 - GET http://google.com/foo1 - begin
|
||||
#0000000100000001 - 1.2.3.4:8765 - GET http://google.com/foo1 - end
|
||||
#0000000100000002 - 1.2.3.4:8765 - POST http://aaa.com/foo2 - begin
|
||||
#0000000100000002 - 1.2.3.4:8765 - POST http://aaa.com/foo2 - end
|
||||
`
|
||||
if cl.out != expectedLogOut {
|
||||
t.Fatalf("Unexpected logger output: %q. Expected %q", cl.out, expectedLogOut)
|
||||
|
||||
Reference in New Issue
Block a user