{"thread":{"id":"17390","subject":"[PATCHv3] gitweb: make static files accessible with PATH_INFO","startedAt":"2009-01-27T13:29:06Z","lastAt":"2009-01-28T00:58:44Z","messageCount":5,"participants":["Giuseppe Bilotta","Jakub Narebski"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"102117","messageId":"1233062946-22395-1-git-send-email-giuseppe.bilotta@gmail.com","threadId":"17390","inReplyTo":null,"subject":"[PATCHv3] gitweb: make static files accessible with PATH_INFO","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-01-27T13:29:06Z","receivedAt":"2009-01-27T13:29:06Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"When PATH_INFO is defined, static files such as the defalt CSS or the\nshortcut icon are not accessible beyond the summary page (e.g. in\nshortlog or commit view).\n\nFix this by adding a <base> tag pointing to the script base URL.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\nOf course, last time I forgot that the BASE href is supposed to be\nabsolute. While Opera apparently has no problem with it being relative,\nother browsers such as Firefox are stricter about it.\n\n gitweb/gitweb.perl |    8 ++++++++\n 1 files changed, 8 insertions(+), 0 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 931db4f..411b1f6 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -2901,6 +2901,14 @@ sub git_header_html {\n <meta name=\"robots\" content=\"index, nofollow\"/>\n <title>$title</title>\n EOF\n+# the stylesheet, favicon etc urls won't work correctly with path_info unless we set the appropriate base URL\n+\tif ($ENV{'PATH_INFO'}) {\n+\t\tmy $base = $my_url;\n+\t\tmy $sname = $ENV{'SCRIPT_NAME'};\n+\t\t$base =~ s,\\Q$sname\\E$,,;\n+\t\t$base .= \"/\";\n+\t\tprint \"<base href=\\\"$base\\\"/>\\n\";\n+\t}\n # print out each stylesheet that exist\n \tif (defined $stylesheet) {\n #provides backwards capability for those people who define style sheet in a config file\n-- \n1.5.6.5\n"},{"id":"102203","messageId":"200901280114.59388.jnareb@gmail.com","threadId":"17390","inReplyTo":"1233062946-22395-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"Re: [PATCHv3] gitweb: make static files accessible with PATH_INFO","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2009-01-28T00:14:58Z","receivedAt":"2009-01-28T00:14:58Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"On Tue, 27 Jan 2009, Giuseppe Bilotta wrote:\n\n> When PATH_INFO is defined, static files such as the defalt CSS or the\n                                                      default\n\n> shortcut icon are not accessible beyond the summary page (e.g. in\n> shortlog or commit view).\n> \n> Fix this by adding a <base> tag pointing to the script base URL.\n\nBy the way, I have thought that it would conflict with use path_info\nfor 'blob_plain' action to have links work in document... but I forgot\nthat then we do not use gitweb HTML header...\n\n> \n> Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n> ---\n> Of course, last time I forgot that the BASE href is supposed to be\n> absolute. While Opera apparently has no problem with it being relative,\n> other browsers such as Firefox are stricter about it.\n\nErrrr... I think you are talking about _full_ vs. _absolute_, not\n_absolute_ vs. _relative_, see below.\n\n> \n>  gitweb/gitweb.perl |    8 ++++++++\n>  1 files changed, 8 insertions(+), 0 deletions(-)\n> \n> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\n> index 931db4f..411b1f6 100755\n> --- a/gitweb/gitweb.perl\n> +++ b/gitweb/gitweb.perl\n> @@ -2901,6 +2901,14 @@ sub git_header_html {\n>  <meta name=\"robots\" content=\"index, nofollow\"/>\n>  <title>$title</title>\n>  EOF\n> +# the stylesheet, favicon etc urls won't work correctly with path_info unless we set the appropriate base URL\n\nErrr... could you please break this line to not have it overly long?\n\n> +\tif ($ENV{'PATH_INFO'}) {\n> +\t\tmy $base = $my_url;\n\nHmmm...\n\n  our $my_url = $cgi->url(); # = $cgi->url(-full);\n  our $my_uri = $cgi->url(-absolute => 1);\n\n> +\t\tmy $sname = $ENV{'SCRIPT_NAME'};\n> +\t\t$base =~ s,\\Q$sname\\E$,,;\n> +\t\t$base .= \"/\";\n\nI don't think that is required; neither of $my_url and $my_uri ends\nwith '/' after stripping path info:\n\n  our $path_info = $ENV{\"PATH_INFO\"};\n  if ($path_info) {\n  \t$my_url =~ s,\\Q$path_info\\E$,,;\n  \t$my_uri =~ s,\\Q$path_info\\E$,,;\n  }\n\nand if BASE is a document, then relative URLs are resolved using\ndirname of BASE, I guess, as\n  http://www.w3.org/TR/html401/struct/links.html#edef-BASE\ncontains in example:\n  <BASE href=\"http://www.aviary.com/products/intro.html\">\n\nSee also RFC1808 (Relative Uniform Resource Locators), section\n4.  Resolving Relative URLs:\n\n   Step 6: The last segment of the base URL's path (anything\n           following the rightmost slash \"/\", or the entire path if no\n           slash is present) is removed and the embedded URL's path is\n           appended in its place.[...]\n\nBesides, if you strip SCRIPT_NAME, then you are left with document\nroot; this means that if git-logo.png etc. are in the same directory\nas gitweb.cgi, they won't be found.  For example for me it doesn't\nwork correctly (I have git-logo.png along gitweb.cgi, which is in\n/cgi-bin/gitweb/... and thanks to symlinks also in /gitweb/).\n\n\nBy the way, according to documentation $cgi->url() should *not*\ncontain path_info; you have to use $cgi->url(-path_info=>1) for\nthat... strange.\n\n> +\t\tprint \"<base href=\\\"$base\\\"/>\\n\";\n\nJust in case, to be compatible with both XHML and HTML, we should use\n\n+\t\tprint \"<base href=\\\"$base\\\" />\\n\";\n\n...if not for the fact that surrounding code doesn't use this way...\n\n> +\t}\n>  # print out each stylesheet that exist\n>  \tif (defined $stylesheet) {\n>  #provides backwards capability for those people who define style sheet in a config file\n> -- \n> 1.5.6.5\n> \n> \n\n-- \nJakub Narebski\nPoland\n"},{"id":"102208","messageId":"cb7bb73a0901271643g7c3a8c42qff6025187ab3c081@mail.gmail.com","threadId":"17390","inReplyTo":"200901280114.59388.jnareb@gmail.com","subject":"Re: [PATCHv3] gitweb: make static files accessible with PATH_INFO","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-01-28T00:43:20Z","receivedAt":"2009-01-28T00:43:20Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"On Wed, Jan 28, 2009 at 1:14 AM, Jakub Narebski <jnareb@gmail.com> wrote:\n> On Tue, 27 Jan 2009, Giuseppe Bilotta wrote:\n>\n>> When PATH_INFO is defined, static files such as the defalt CSS or the\n>                                                      default\n>\n>> shortcut icon are not accessible beyond the summary page (e.g. in\n>> shortlog or commit view).\n>>\n>> Fix this by adding a <base> tag pointing to the script base URL.\n>\n> By the way, I have thought that it would conflict with use path_info\n> for 'blob_plain' action to have links work in document... but I forgot\n> that then we do not use gitweb HTML header...\n>\n>>\n>> Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n>> ---\n>> Of course, last time I forgot that the BASE href is supposed to be\n>> absolute. While Opera apparently has no problem with it being relative,\n>> other browsers such as Firefox are stricter about it.\n>\n> Errrr... I think you are talking about _full_ vs. _absolute_, not\n> _absolute_ vs. _relative_, see below.\n\nNo, I actually mean absolute vs relative in the URI sense, not in the\nPerl/CGI sense.\n\nhttp://www.example.com/ is absolute, / is relative\n\n>>  gitweb/gitweb.perl |    8 ++++++++\n>>  1 files changed, 8 insertions(+), 0 deletions(-)\n>>\n>> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\n>> index 931db4f..411b1f6 100755\n>> --- a/gitweb/gitweb.perl\n>> +++ b/gitweb/gitweb.perl\n>> @@ -2901,6 +2901,14 @@ sub git_header_html {\n>>  <meta name=\"robots\" content=\"index, nofollow\"/>\n>>  <title>$title</title>\n>>  EOF\n>> +# the stylesheet, favicon etc urls won't work correctly with path_info unless we set the appropriate base URL\n>\n> Errr... could you please break this line to not have it overly long?\n\nAh yes, sorry.\n\n>> +     if ($ENV{'PATH_INFO'}) {\n>> +             my $base = $my_url;\n>\n> Hmmm...\n>\n>  our $my_url = $cgi->url(); # = $cgi->url(-full);\n>  our $my_uri = $cgi->url(-absolute => 1);\n>> +             my $sname = $ENV{'SCRIPT_NAME'};\n>> +             $base =~ s,\\Q$sname\\E$,,;\n>> +             $base .= \"/\";\n>\n> I don't think that is required; neither of $my_url and $my_uri ends\n> with '/' after stripping path info:\n>\n>  our $path_info = $ENV{\"PATH_INFO\"};\n>  if ($path_info) {\n>        $my_url =~ s,\\Q$path_info\\E$,,;\n>        $my_uri =~ s,\\Q$path_info\\E$,,;\n>  }\n>\n> and if BASE is a document, then relative URLs are resolved using\n> dirname of BASE, I guess, as\n>  http://www.w3.org/TR/html401/struct/links.html#edef-BASE\n> contains in example:\n>  <BASE href=\"http://www.aviary.com/products/intro.html\">\n>\n> See also RFC1808 (Relative Uniform Resource Locators), section\n> 4.  Resolving Relative URLs:\n>\n>   Step 6: The last segment of the base URL's path (anything\n>           following the rightmost slash \"/\", or the entire path if no\n>           slash is present) is removed and the embedded URL's path is\n>           appended in its place.[...]\n\nAh, good point, I had missed this part, so we can actually keep the\nscript name in the url. Good.\n\n> Besides, if you strip SCRIPT_NAME, then you are left with document\n> root; this means that if git-logo.png etc. are in the same directory\n> as gitweb.cgi, they won't be found.  For example for me it doesn't\n> work correctly (I have git-logo.png along gitweb.cgi, which is in\n> /cgi-bin/gitweb/... and thanks to symlinks also in /gitweb/).\n\nThey won't be found only if you have gitweb.cgi as directory index. In\nthat case you obviously need a rewrite rule at the server level\nanyway. The one I use is\n\nRewriteEngine On\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteRule ^.* gitweb.cgi/$0 [L,PT]\n\ntha means 'server static files and turn anything else into pathinfo\nfor gitweb.cgi'\n\nWe probably want to document that. Notice that it's an issue\nregardless of this particular patch.\n\n> By the way, according to documentation $cgi->url() should *not*\n> contain path_info; you have to use $cgi->url(-path_info=>1) for\n> that... strange.\n\nI think there's a bug in CGI.pm when the script is the directory index.\n\n>> +             print \"<base href=\\\"$base\\\"/>\\n\";\n>\n> Just in case, to be compatible with both XHML and HTML, we should use\n>\n> +               print \"<base href=\\\"$base\\\" />\\n\";\n\n> ...if not for the fact that surrounding code doesn't use this way...\n\nThat's the reason why I kept it that way, yes.\n\n-- \nGiuseppe \"Oblomov\" Bilotta\n"},{"id":"102210","messageId":"200901280155.26399.jnareb@gmail.com","threadId":"17390","inReplyTo":"cb7bb73a0901271643g7c3a8c42qff6025187ab3c081@mail.gmail.com","subject":"Re: [PATCHv3] gitweb: make static files accessible with PATH_INFO","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2009-01-28T00:55:26Z","receivedAt":"2009-01-28T00:55:26Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"On Wed, 28 Jan 2009, Giuseppe Bilotta wrote:\n> On Wed, Jan 28, 2009 at 1:14 AM, Jakub Narebski <jnareb@gmail.com> wrote:\n> > On Tue, 27 Jan 2009, Giuseppe Bilotta wrote:\n\n> > > Of course, last time I forgot that the BASE href is supposed to be\n> > > absolute. While Opera apparently has no problem with it being relative,\n> > > other browsers such as Firefox are stricter about it.\n> >\n> > Errrr... I think you are talking about _full_ vs. _absolute_, not\n> > _absolute_ vs. _relative_, see below.\n> \n> No, I actually mean absolute vs relative in the URI sense, not in the\n> Perl/CGI sense.\n> \n> http://www.example.com/ is absolute, / is relative\n\nNo, \"/\" is not relative, it is absolute, because it begins with '/'.\nSee RFC 1808 (Relative Uniform Resource Locators):\n\n 2.2.  BNF for Relative URLs\n\n [...]\n\n   URL         = ( absoluteURL | relativeURL ) [ \"#\" fragment ]\n\n   absoluteURL = generic-RL | ( scheme \":\" *( uchar | reserved ) )\n\n   generic-RL  = scheme \":\" relativeURL\n\n   relativeURL = net_path | abs_path | rel_path\n\n   net_path    = \"//\" net_loc [ abs_path ]\n   abs_path    = \"/\"  rel_path\n   rel_path    = [ path ] [ \";\" params ] [ \"?\" query ]\n\n(which means that CGI.pm -full is 'net_path', and -absolute is\n'abs_path', and -relative is 'rel_path')\n\n [...]\n\n 4.  Resolving Relative URLs\n\n  [...]\n\n     Step 4: If the embedded URL path is preceded by a slash \"/\", the\n           path is not relative and we skip to Step 7.\n\n\n-- \nJakub Narebski\nPoland\n"},{"id":"102211","messageId":"200901280158.44386.jnareb@gmail.com","threadId":"17390","inReplyTo":"200901280155.26399.jnareb@gmail.com","subject":"Re: [PATCHv3] gitweb: make static files accessible with PATH_INFO","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2009-01-28T00:58:44Z","receivedAt":"2009-01-28T00:58:44Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Jakub Narebski wrote:\n> On Wed, 28 Jan 2009, Giuseppe Bilotta wrote:\n> > On Wed, Jan 28, 2009 at 1:14 AM, Jakub Narebski <jnareb@gmail.com> wrote:\n> > > On Tue, 27 Jan 2009, Giuseppe Bilotta wrote:\n> \n> > > > Of course, last time I forgot that the BASE href is supposed to be\n> > > > absolute. While Opera apparently has no problem with it being relative,\n> > > > other browsers such as Firefox are stricter about it.\n> > >\n> > > Errrr... I think you are talking about _full_ vs. _absolute_, not\n> > > _absolute_ vs. _relative_, see below.\n> > \n> > No, I actually mean absolute vs relative in the URI sense, not in the\n> > Perl/CGI sense.\n> > \n> > http://www.example.com/ is absolute, / is relative\n> \n> No, \"/\" is not relative, it is absolute, because it begins with '/'.\n\nOoops, sorry, I mistook absolute _path_ for absolute _URL_. \nNevertheless path beginning with \"/\" inherits only net_loc (host).\n\n-- \nJakub Narebski\nPoland\n"}]}