poeml / mirrorbrain

MirrorBrain
http://mirrorbrain.org/
Other
75 stars 37 forks source link

mod_stats: capture mirror address and file size #177

Closed chrisvwn closed 5 years ago

chrisvwn commented 5 years ago

I am trying to modify mod_stats.c to capture and log requests redirected to mirrors. In particular, I want to capture the chosen mirror and file size which I see listed in the mirrorbrain log. However, I am not sure if mod_stats receives the redirected request or the original request.

When I test for r->next it seems to be null which makes me think that this is the request before mirrorbrain has appended the redirect? Is this how I would access the mirror that the request has been redirected to?

    if(r->next)
      d->mirr = r->next->hostname;

Maybe I am totally in the wrong place as I am new to this.

So what I would like to do is extract filename (done), mirror (not done), filesize (not done).

poeml commented 5 years ago

Hi Chris,

Does this work for the file size?

apr_off_t_toa(r->pool, r->finfo.size));

For the mirror name, unless you want to split it from the redirection URL, you could read it from a header that mod_mirrorbrain sets like this:

apr_table_setn(r->err_headers_out, "X-MirrorBrain-Mirror", chosen->identifier);

The mod_mirrorbrain internal data won’t be accessible from mod_stats; but the headers are. (I have forgotten about other/better ways to pass data from module to module, at the moment.)

Mod_stats receives the original request; it just runs later, because it uses the so called logging hook of the Apache Module API (which always is run last, after any other hook).

Am 21.02.2019 um 22:44 schrieb Chris Njuguna notifications@github.com:

I am trying to modify mod_stats.c to capture and log requests redirected to mirrors. In particular, I want to capture the chosen mirror and file size which I see listed in the mirrorbrain log. However, I am not sure if mod_stats receives the redirected request or the original request.

When I test for r->next it seems to be null which makes me think that this is the request before mirrorbrain has appended the redirect? Is this how I would access the mirror that the request has been redirected to?

if(r->next)
  d->mirr = r->next->hostname;

Maybe I am totally in the wrong place as I am new to this.

So what I would like to do is extract filename (done), mirror (not done), filesize (not done).

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

chrisvwn commented 5 years ago

Thanks @poeml these worked.

apr_table_get(r->err_headers_out, "X-MirrorBrain-Mirror") gives me (null) but should be perfect once I get the dbd error in my other issue fixed.