Http Access Log

108 views
Skip to first unread message

Denis Rossi

unread,
Nov 25, 2016, 4:52:33 AM11/25/16
to Netty discussions
Hi,

I'm implementing an HTTP server with netty 4.1.6.Final, and I would like to implement an access log.
This is what I would like to do, considering that I'm trying to never call writeAndFlush but just write and flush is called only when a read complete event has been fired:
  1. get the start time before the the message is decoded to an HttpRequest (before the HTTP codec)
  2. get method, protocol, uri, x-forwarded-for and x-forwarded-proto headers immediately after the message has been decoded in a HTTP request
  3. get response status and content length when I write the HTTP response
  4. get the response time when I flush

The problem I'm facing is that I cannot keep trace of all those informations as channel attributes cause a read operation could happen before the flush is called.

Even if I try to keep those information grouped by a messageId set at the very first read, I cannot know, when I flush, to which original message I'm responding.


Does it makes sense? Am I approaching the problem in a wrong way?


Thanks for helping.


Regards,

Denis Rossi

俞超

unread,
Nov 25, 2016, 7:48:42 PM11/25/16
to ne...@googlegroups.com
hi, Denis, try this to see if follows could help you ^^


in Handler which extends HTTP codec
1. generate a messageId and record startTime and something others in a data struct in this channel attr or in a global data struct
2. decode a http request
3. put the messageId in http request headers


in HttpRequestHandler
1. pull the messageId in httpRequest header
2. record something with messageId
3. do business
4.
response.headers().set(CONNECTION, KEEP_ALIVE);
ctx.write(response).addListener(new GenericFutureListener<Future<? super Void>>() {
    // this method is called after flush() method
    @Override
    public void operationComplete(Future<? super Void> future) throws Exception {
        future.isSuccess();
        // do something with messageId
    }
});


--
You received this message because you are subscribed to the Google Groups "Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netty+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netty/bd4b6427-7c24-4557-b589-f4381bfe2925%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages