Hi,<br>
<br>
I know that I can customize my error pages (404, ...) with "error.num" key (ex : error.404 myError.html) in kloned.conf.<br>
But I wish use the same error page (.kl1 or .klx) for all errors.<br>
To do this I must give a GET or POST variable at my error page (ex : error.kl1?no=404).<br>
<br>
For example :<br>
<br>
(kloned.conf)<br>
=================================================<br>
app_http<br>
{<br>
type http<br>
addr.type IPv4<br>
addr.port 80<br>
dir_root /www<br>
<br>
error<br>
{<br>
400 /error.kl1?no=400<br>
404 /error.kl1?no=404<br>
...<br>
}<br>
}<br>
=================================================<br>
<br>
(error.kl1)<br>
=================================================<br>
<%!<br>
static const char *errorno;<br>
%><%<br>
errorno = request_get_arg(request,"no");<br>
%><html><br>
<body><br>
<h1><%= errorno %> Error</h1><br>
</body><br>
</html><br>
=================================================<br>
<br>
However this example doesn't actually.<br>
<br><br>I have searched a solution to perform this.<br>If I comment the line 421 "if(http_is_valid_uri(rq, err_page, strlen(err_page)))"<br>of "http_print_error_page()" function in "src/libhttp/http.c", my custom error page with GET parameter is printed in my web-browser.<br>
So the solution is to modify "http_print_error_page()" function OR to pass the single URL (without GET parameter) at this function. It should be just see the base of URI is valid (ex : <a href="http://localhost/myerror.kl1?no=404">http://localhost/myerror.kl1?no=404</a> => <a href="http://localhost/myerror.kl1">http://localhost/myerror.kl1</a> ).<br>
<br>Here a solution that I tested with successfull :<br>
=================================================<br>static int http_print_error_page(http_t *h, request_t *rq, response_t *rs, <br> int http_status)<br>{<br> enum { BUFSZ = 64 };<br> const char *err_page;<br> char buf[BUFSZ];<br>
vhost_t *vhost;<br><br> int i; // new meter for new "for" loop<br> char uri[255]; // URL wihout GET parameter. 255 is the max length of URL<br><br> dbg_err_if (h == NULL);<br> dbg_err_if (rq == NULL);<br>
dbg_err_if (rs == NULL);<br> dbg_err_if (http_status == 0);<br> <br> /* clean dirty header fields (not for redirects) */<br> if(http_status != 302)<br> dbg_err_if(header_clear(response_get_header(rs)));<br>
<br> /* add default header fields */<br> dbg_err_if(http_add_default_header(h, rq, rs));<br><br> /* disable page caching */<br> dbg_err_if(response_disable_caching(rs));<br><br> /* looking for user provided error page */<br>
dbg_err_if(u_snprintf(buf, BUFSZ, "error.%d", http_status));<br> if((vhost = http_get_vhost(h, rq)) == NULL)<br> err_page = u_config_get_subkey_value(h->config, buf);<br> else<br> err_page = u_config_get_subkey_value(vhost->config, buf);<br>
<br> if(err_page && !request_set_uri(rq, err_page, NULL, NULL))<br> {<br> dbg_err_if(http_resolv_request(h, rq));<br> <br> //copy of err_page without GET parameter<br> memset(uri,'\0',255);<br>
for(i=0;i<strlen(err_page);i++)<br> {<br> if(err_page[i]=='?')<br> break;<br> uri[i]=err_page[i];<br> } <br> //if(http_is_valid_uri(rq, err_page, strlen(err_page))) //old test of URI<br>
if(http_is_valid_uri(rq, uri, strlen(uri))) //new test of URI<br> {<br> /* user provided error page found */<br> broker_serve(h->broker, h, rq, rs);<br> return 0;<br> }<br>
<br> /* page not found */<br> warn("%d handler page (%s) not found", http_status, err_page);<br> }<br><br> /* be sure that the status code is properly set */<br> response_set_status(rs, http_status);<br>
<br> response_print_header(rs);<br><br> if(request_get_method(rq) == HM_HEAD)<br> return 0; /* just the header is requested */<br><br> /* print default error page */<br> dbg_err_if(io_printf(response_io(rs), <br>
"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">"<br> "<html><head><title>%d %s</title></head>\n"<br> "<body><h1>%s</h1><p>URL: %s</p><hr>"<br>
"<address>KLone/%s web server - <a href="http://www.koanlogic.com">www.koanlogic.com</a></address>"<br> "</body></html>", <br> http_status, http_get_status_desc(http_status), <br>
http_get_status_desc(http_status), <br> (request_get_uri(rq) ? request_get_uri(rq) : ""),<br> KLONE_VERSION<br> ) < 0);<br><br> return 0;<br>err:<br> return ~0;<br>}<br>
=================================================<br><br>In this solution, I choose 255 for the max length of URI. This value should be your value that I don't known.<br><br>What do you think of this solution ?<br>
<br><br>
Bye.<br clear="all"><br>-- <br>Mickaël AUGER<br><br>