[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH][Feature request] global.cgi: Add a fallback redirect method for

From: Alain Kalker
Subject: [PATCH][Feature request] global.cgi: Add a fallback redirect method for webservers which do not support CGI redirects
Date: Fri, 08 Feb 2013 00:10:56 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130109 Thunderbird/17.0.2

It is possible (and very convenient :-) ) to serve the website generated by `htags --suggest2` using nothing more than:

$ pwd > GTAGSROOT # to enable global.cgi to find the tags files
$ (cd HTML; python -m http.server --cgi) # Python 3.x
$ (cd HTML; python -m CGIHTTPServer) # Python 2.x

and browsing to: http://localhost:8000/index.html
(The .../index.html is required, as Python doesn't map / path to /index.html automatically.)

However, Python's built-in webserver (and possibly some others) doesn't support redirects issued from CGI scripts, so when a search returns only 1 result, users will see a blank page instead of the source page with the result. This patch addresses this problem by sending an HTML snippet in the response body (yes, the standards allow for this!) to make the browser perform the redirect on its own, using the "META Refresh" method. The extra data sent shouldn't have any effect on servers which do support CGI redirects. I've left room for a secondary fallback by including a link in the <body></body> block, in case the refresh method doesn't work either. The refresh method is deprecated, but I hope that by the time it isn't supported anymore, the CGI redirection problem will be fixed in the webservers anyway.

Tested using:
OS: Arch Linux (rolling release)
Packages: GNU GLOBAL 6.2.7, Perl v5.16.2
Servers: Apache 2.2.23, Python 2.7.3, Python 3.3.0
Browsers: Chromium 24.0.1312.68, Firefox 18.0.2, Opera 12.14.1738

Signed-off-by: Alain Kalker <address@hidden>

diff -aur global-6.2.7.pristine/htags/global.cgi.tmpl.in global-6.2.7.new/htags/global.cgi.tmpl.in --- global-6.2.7.pristine/htags/global.cgi.tmpl.in 2012-12-22 01:43:58.000000000 +0100 +++ global-6.2.7.new/htags/global.cgi.tmpl.in 2013-02-07 14:56:38.317009059 +0100
@@ -181,6 +181,10 @@
     # direct jump
     ($fid, $tag, $lno, $filename) = split(/[ \t]+/, shift @line);
     print "Location: $basedir/S/$fid.$html#L$lno\n\n";
+    print "<html>\n";
+ print qq(<head><meta http-equiv="Refresh" content="0; url=$basedir/S/$fid.$html#L$lno" /></head>\n);
+    print "<body></body>\n";
+    print "</html>\n";
     exit 0;
 print header();

reply via email to

[Prev in Thread] Current Thread [Next in Thread]