Hi,
I'm currently trying to add the ability to redirect requests for the
initial html page to a captcha page when there is no session or no valid
session. Currently I'm doing this in the fixups hook:
mod_smu_fixups(request_rec* r) {
const char * content_type_str_p;
const char * content_len_str_p;
/* Get the modules config vector. */
MOD_SMU_SERVER_CFG_T * const smu_svr_cfg_p = ap_get_module_config(
r->server->module_config,
&smu_module);
if(DEBUG_ENABLED & DEBUG_SMU) {
ap_log_rerror(APLOG_MARK, APLOG_NOTICE, 0, r,
"SMU Module Fixups %s (%s)",
r->method, r->filename);
ap_log_rerror(APLOG_MARK, APLOG_NOTICE, 0, r,
"SMU Module Fixups init-req(%d) handler(%s)
content-type(%s)",
ap_is_initial_req(r), r->handler, r->content_type);
}
/*
* If we are being requested for the captcha image then send this
request
* to the smu-captcha content generator which will generate it on
the fly.
*/
if(smu_captcha_is_image_request(r)) {
ap_log_rerror(APLOG_MARK, APLOG_NOTICE, 0, r,
"SMU Fixup CAPTCHA Image (%s)", r->filename);
r->handler = "application/smu-captcha";
return OK;
}
/* If this is the initial request (ie not a sub request) clear the
error
* and command list */
if(ap_is_initial_req(r)) {
/* First up ensure that the error and command list are empty */
mod_smu_list_empty(smu_svr_cfg_p->command_list_p);
/* Empty error list */
mod_smu_list_empty(smu_svr_cfg_p->error_list_p);
/* Check to see if a captcha page is needed. */
if(captcha_display_needed(r)
&& apr_strnatcasecmp(r->content_type, "text/html") == 0
) {
//r->handler = "application/smu_captcha";
//ap_internal_redirect("/captcha.shtml", r);
ap_log_rerror(APLOG_MARK, APLOG_NOTICE, 0, r,
"SMU Fixup CAPTCHA needed (%s)", r->filename);
ap_internal_redirect_handler("/captcha.shtml", r);
return OK;
}
}
....
}
So if we have an initial request that is HTML then redirect to
captcha.shtml which contains SSI for header, footer etc. There will
also be a request for a captcha image using a fixed filename. The fixup
will detect this and send the request to a custom handler that will
auto-generate the captcha image. The problem I have is that I'm getting
sub-requests and requests for the captcha image twice, see log below. I
assume that the original request for index.shtml and the request for
captcha.shtml are being processed. Using firebug I see that the captcha
image that is displayed in the debug output isn't the one that gets
displayed in the HTML so I can assume that the image is being sent
twice. I notice that the browser goes into a waiting state until the
timeout expires. Does anybody know what I'm doing wrong? I've tried
returning DECLINED or DONE after the ap_internal_redirect_handler call
but still get the problem. Any help appreciated.
Best Regards,
Martin.
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Fixup
CAPTCHA needed (/var/www/index.shtml), referer:
http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Module
Fixups GET (/var/www/captcha.shtml), referer:
http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Module
Fixups init-req(0) handler((null)) content-type(text/html), referer:
http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Module
Fixups GET (/var/www/include/SSI_PageHead.html), referer:
http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Module
Fixups init-req(0) handler((null)) content-type(text/html), referer:
http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Module
Fixups GET (/var/www/include/SSI_PageTop.html), referer:
http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Module
Fixups init-req(0) handler((null)) content-type(text/html), referer:
http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Module
Fixups GET (/var/www/include/SSI_Contents.html), referer:
http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Module
Fixups init-req(0) handler((null)) content-type(text/html), referer:
http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Module
Fixups GET (/var/www/include/SSI_PageFooter.html), referer:
http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Module
Fixups init-req(0) handler((null)) content-type(text/html), referer:
http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Module
Fixups GET (/var/www/include/SSI_PageHead.html), referer:
http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Module
Fixups init-req(0) handler((null)) content-type(text/html), referer:
http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Module
Fixups GET (/var/www/include/SSI_PageTop.html), referer:
http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Module
Fixups init-req(0) handler((null)) content-type(text/html), referer:
http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Module
Fixups GET (/var/www/include/SSI_Contents.html), referer:
http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Module
Fixups init-req(0) handler((null)) content-type(text/html), referer:
http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Module
Fixups GET (/var/www/include/SSI_PageFooter.html), referer:
http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Module
Fixups init-req(0) handler((null)) content-type(text/html), referer:
http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Module
Fixups GET (/var/www/sscd.css), referer: http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Module
Fixups init-req(1) handler((null)) content-type(text/css), referer:
http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Module
Fixups GET (/var/www/captcha_image.gif), referer:
http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Module
Fixups init-req(1) handler((null)) content-type(image/gif), referer:
http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] SMU Fixup
CAPTCHA Image (/var/www/captcha_image.gif), referer:
http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:41 2010] [notice] [client 192.168.1.70] smu-captcha
/var/www/captcha_image.gif, referer: http://192.168.0.52/index.shtml
[Wed Aug 18 12:39:44 2010] [notice] [client 192.168.1.70] SMU Module
Fixups GET (/var/www/captcha_image.gif)
[Wed Aug 18 12:39:44 2010] [notice] [client 192.168.1.70] SMU Module
Fixups init-req(1) handler((null)) content-type(image/gif)
[Wed Aug 18 12:39:44 2010] [notice] [client 192.168.1.70] SMU Fixup
CAPTCHA Image (/var/www/captcha_image.gif)
[Wed Aug 18 12:39:44 2010] [notice] [client 192.168.1.70] smu-captcha
/var/www/captcha_image.gif