{"thread":{"id":"25858","subject":"Re: gitweb: false base href sent when integrated via reverse proxy and path_info is active","startedAt":"2010-11-28T16:27:20Z","lastAt":"2010-12-01T03:25:10Z","messageCount":15,"participants":["Jonathan Nieder","Giuseppe Bilotta","Jakub Narebski","Daniel Reichelt","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"156755","messageId":"20101128162720.GB18335@burratino","threadId":"25858","inReplyTo":"20101128081048.13668.67286.reportbug@sb74.startrek","subject":"Re: gitweb: false base href sent when integrated via reverse proxy and path_info is active","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-11-28T16:27:20Z","receivedAt":"2010-11-28T16:27:20Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi Jakub et al,\n\nDaniel Reichelt wrote[1]:\n\n> I just noticed that integrating gitweb via reverse proxy is impossible when\n> path_info is enabled in gitweb.conf. The base href sent on gitweb.cgi:3427\n> contains the \"internal\" URL called by the reverse proxy mechanism, not the\n> original one called by the user agent which makes it impossible for the\n> client to display CSS, images, etc...\n> \n> I suggest an additional config variable, e.g.\n> $feature{'pathinfo'}{'basehrefoverride'} which could override the base href\n> tag determinted by the cgi script (or disable sending a base href tag at all\n> - at least I was able to achieve my desired setup by adjusting the URLs for\n> CSS etc in gitweb.conf to fitting absolute URLs).\n\nAny advice for Daniel?  Is it a good idea?\n\nRegards,\nJonathan\n\n[1] http://bugs.debian.org/605217\n"},{"id":"156756","messageId":"AANLkTinM8qyL9DafMx4XWBQ5RUeWABKVc5mNjdVEkQfZ@mail.gmail.com","threadId":"25858","inReplyTo":"20101128162720.GB18335@burratino","subject":"Re: gitweb: false base href sent when integrated via reverse proxy and path_info is active","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2010-11-28T17:25:48Z","receivedAt":"2010-11-28T17:25:48Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"On Sun, Nov 28, 2010 at 5:27 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Hi Jakub et al,\n>\n> Daniel Reichelt wrote[1]:\n>\n>> I just noticed that integrating gitweb via reverse proxy is impossible when\n>> path_info is enabled in gitweb.conf. The base href sent on gitweb.cgi:3427\n>> contains the \"internal\" URL called by the reverse proxy mechanism, not the\n>> original one called by the user agent which makes it impossible for the\n>> client to display CSS, images, etc...\n>>\n>> I suggest an additional config variable, e.g.\n>> $feature{'pathinfo'}{'basehrefoverride'} which could override the base href\n>> tag determinted by the cgi script (or disable sending a base href tag at all\n>> - at least I was able to achieve my desired setup by adjusting the URLs for\n>> CSS etc in gitweb.conf to fitting absolute URLs).\n>\n> Any advice for Daniel?  Is it a good idea?\n\nI'm not familiar with the way reverse proxies operate. Is there some\ninformation that the script can scrape to understand that its request\nis being reverse-proxied? Or are there options that the reverse\nproxies can be configured with to pretend that the URL is not being\nrewritten? These would be better solutions.\n\nLacking that, a plain\n\nour $base_url  = 'whatever';\n\nin the gitweb config should probably work, as the gitweb config is\nevaluated _after_ the internal URI variables are set. Can the bug\nsubmitter confirm that this does indeed work?\n\n-- \nGiuseppe \"Oblomov\" Bilotta\n"},{"id":"156757","messageId":"201011281847.40233.jnareb@gmail.com","threadId":"25858","inReplyTo":"AANLkTinM8qyL9DafMx4XWBQ5RUeWABKVc5mNjdVEkQfZ@mail.gmail.com","subject":"Re: gitweb: false base href sent when integrated via reverse proxy and path_info is active","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2010-11-28T17:47:38Z","receivedAt":"2010-11-28T17:47:38Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"On Sun, 28 Nov 2010, Giuseppe Bilotta wrote:\n> On Sun, Nov 28, 2010 at 5:27 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n>> Hi Jakub et al,\n>>\n>> Daniel Reichelt wrote[1]:\n>>\n>>> I just noticed that integrating gitweb via reverse proxy is impossible when\n>>> path_info is enabled in gitweb.conf. The base href sent on gitweb.cgi:3427\n>>> contains the \"internal\" URL called by the reverse proxy mechanism, not the\n>>> original one called by the user agent which makes it impossible for the\n>>> client to display CSS, images, etc...\n>>>\n>>> I suggest an additional config variable, e.g.\n>>> $feature{'pathinfo'}{'basehrefoverride'} which could override the base href\n>>> tag determinted by the cgi script (or disable sending a base href tag at all\n>>> - at least I was able to achieve my desired setup by adjusting the URLs for\n>>> CSS etc in gitweb.conf to fitting absolute URLs).\n>>\n>> Any advice for Daniel?  Is it a good idea?\n> \n> I'm not familiar with the way reverse proxies operate. Is there some\n> information that the script can scrape to understand that its request\n> is being reverse-proxied? Or are there options that the reverse\n> proxies can be configured with to pretend that the URL is not being\n> rewritten? These would be better solutions.\n> \n> Lacking that, a plain\n> \n> our $base_url  = 'whatever';\n> \n> in the gitweb config should probably work, as the gitweb config is\n> evaluated _after_ the internal URI variables are set. Can the bug\n> submitter confirm that this does indeed work?\n\nSee also gitweb/README, the \"Gitweb config file variables\" section:\n\n * $base_url\n   Base URL for relative URLs in pages generated by gitweb,\n   (e.g. $logo, $favicon, @stylesheets if they are relative URLs),\n   needed and used only for URLs with nonempty PATH_INFO via\n   <base href=\"$base_url\">.  Usually gitweb sets its value correctly,\n                             ^^^^^^^\n   and there is no need to set this variable, e.g. to $my_uri or \"/\".\n\nThe key word here is \"usually\" ;-)\n\n-- \nJakub Narebski\nPoland\n"},{"id":"156758","messageId":"20101128181215.GB19545@burratino","threadId":"25858","inReplyTo":"201011281847.40233.jnareb@gmail.com","subject":"Re: gitweb: false base href sent when integrated via reverse proxy and path_info is active","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-11-28T18:12:15Z","receivedAt":"2010-11-28T18:12:15Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Jakub Narebski wrote:\n\n> See also gitweb/README, the \"Gitweb config file variables\" section:\n> \n>  * $base_url\n>    Base URL for relative URLs in pages generated by gitweb,\n>    (e.g. $logo, $favicon, @stylesheets if they are relative URLs),\n>    needed and used only for URLs with nonempty PATH_INFO via\n>    <base href=\"$base_url\">.  Usually gitweb sets its value correctly,\n>                              ^^^^^^^\n>    and there is no need to set this variable, e.g. to $my_uri or \"/\".\n> \n> The key word here is \"usually\" ;-)\n\nThanks, all.  That helps.\n\nNo time for it at the moment, but I'm taking this as evidence that\nwe need a gitweb.conf(5) manual page. :)  Would you be interested\nin such a thing (as POD or asciidoc)?\n\nJonathan\n"},{"id":"156773","messageId":"4CF2BBEE.2050808@nachtgeist.net","threadId":"25858","inReplyTo":"201011281847.40233.jnareb@gmail.com","subject":"Re: gitweb: false base href sent when integrated via reverse proxy and path_info is active","fromName":"Daniel Reichelt","fromEmail":"debian@nachtgeist.net","sentAt":"2010-11-28T20:30:38Z","receivedAt":"2010-11-28T20:30:38Z","isPatch":false,"sender":{"key":"debian@nachtgeist.net","avatar":null},"body":"Hi all\n\n>> I'm not familiar with the way reverse proxies operate. Is there some\n>> information that the script can scrape to understand that its request\n>> is being reverse-proxied?\n\nNope. Reverse proxy works like this:\n- a \"public\" apache VirtualHost receives an http(s) request for a\ncertain URL /a/b/c... and has the location /a/.* configured as a\nrevProxy location\n- the public vhost repeats that request to the revProxy target\n- the revProxy target receives a request from the \"public\" vhost and\nserves it as usual (this is were the gitweb.cgi script actually is run,\nonly seeing the request made by the public vhost, not the initially\nrequesting client, thus all information about the publicly visible git\nURI is lost and never gets passed on to gitweb.cgi)\n- the public vhost receives the response and forwards it to the client,\npretending he himself had answered the request\n\n\n>> Lacking that, a plain\n>>\n>> our $base_url  = 'whatever';\n>>\n>> in the gitweb config should probably work\n\nNope again, I'm afraid it doesn't (see further down)\n\n\n> See also gitweb/README, the \"Gitweb config file variables\" section:\n> \n>  * $base_url\n>    Base URL for relative URLs in pages generated by gitweb,\n>    (e.g. $logo, $favicon, @stylesheets if they are relative URLs),\n>    needed and used only for URLs with nonempty PATH_INFO via\n>    <base href=\"$base_url\">.  Usually gitweb sets its value correctly,\n>                              ^^^^^^^\n>    and there is no need to set this variable, e.g. to $my_uri or \"/\".\n> \n> The key word here is \"usually\" ;-)\n> \n\n*oops* thank you all for the hint! I totally missed that.\n\nHowever, I just tried that and it failed. $base_url gets ignored in\ngitweb.conf and even setting $my_url and $my_uri in gitweb.conf seems to\nhave no effect at all. For testing purposes I printed the relevant\nvariables to the html header:\n\n\ngitweb.conf:\n************\nour $feature{'pathinfo'}{'default'} = [1];\nour $base_url = \"https://foobar\";\nour $my_url = \"https://foo\";\nour $my_uri = \"https://bar\";\n************\n\ngitweb.cgi:3424\n************\n# the stylesheet, favicon etc urls won't work correctly with path_info\n# unless we set the appropriate base URL\nif ($ENV{'PATH_INFO'}) {\n        print \"<base href=\\\"\".esc_url($base_url).\"\\\" />\\n\";\n}\nprint \"<!--\n$base_url\n$my_url\n$my_uri\n-->\";\n************\n\n\n- git repo listing\npublic url: https://sb74/projects/gitweb\nrevProxy url: https://localhost:446/projects/gitweb\n************\n<head>\n<meta http-equiv=\"content-type\" content=\"application/xhtml+xml;\ncharset=utf-8\"/>\n<meta name=\"generator\" content=\"gitweb/1.7.2.3 git/1.7.2.3\"/>\n<meta name=\"robots\" content=\"index, nofollow\"/>\n<title>localhost Git</title>\n<!--\n\t\thttps://sb74:446/projects/gitweb\n\t\thttps://sb74:446/projects/gitweb\n\t\t/projects/gitweb\n\t\t--><link rel=\"stylesheet\" type=\"text/css\"\nhref=\"/projects/gitweb/gitweb/gitweb.css\"/>\n<link rel=\"alternate\" title=\"localhost Git projects list\"\nhref=\"/projects/gitweb?a=project_index\" type=\"text/plain; charset=utf-8\" />\n<link rel=\"alternate\" title=\"localhost Git projects feeds\"\nhref=\"/projects/gitweb?a=opml\" type=\"text/x-opml\" />\n<link rel=\"shortcut icon\" href=\"/projects/gitweb/gitweb/git-favicon.png\"\ntype=\"image/png\" />\n</head>\n************\n\n\n- git summary of repo \"test1\"\npublic url: https://sb74/projects/gitweb/test1/summary\nrevProxy url: https://localhost:446/projects/gitweb/test1/summary\n************\n<head>\n<meta http-equiv=\"content-type\" content=\"application/xhtml+xml;\ncharset=utf-8\"/>\n<meta name=\"generator\" content=\"gitweb/1.7.2.3 git/1.7.2.3\"/>\n<meta name=\"robots\" content=\"index, nofollow\"/>\n<title>localhost Git - test1/summary</title>\n<base href=\"https://sb74:446/projects/gitweb\" />\n<!--\n\t\thttps://sb74:446/projects/gitweb\n\t\thttps://sb74:446/projects/gitweb\n\t\t/projects/gitweb\n\t\t--><link rel=\"stylesheet\" type=\"text/css\"\nhref=\"/projects/gitweb/gitweb/gitweb.css\"/>\n<link rel=\"alternate\" title=\"test1 - log - RSS feed\"\nhref=\"/projects/gitweb/test1/rss\" type=\"application/rss+xml\" />\n<link rel=\"alternate\" title=\"test1 - log - RSS feed (no merges)\"\nhref=\"/projects/gitweb/test1/rss?opt=--no-merges\"\ntype=\"application/rss+xml\" />\n<link rel=\"alternate\" title=\"test1 - log - Atom feed\"\nhref=\"/projects/gitweb/test1/atom?opt=--no-merges\"\ntype=\"application/atom+xml\" />\n<link rel=\"alternate\" title=\"test1 - log - Atom feed (no merges)\"\nhref=\"/projects/gitweb/test1/atom?opt=--no-merges\"\ntype=\"application/atom+xml\" />\n\n<link rel=\"shortcut icon\" href=\"/projects/gitweb/gitweb/git-favicon.png\"\ntype=\"image/png\" />\n</head>\n************\n\nAny ideas?\n\nRegards\nDaniel\n"},{"id":"156774","messageId":"201011282207.03261.jnareb@gmail.com","threadId":"25858","inReplyTo":"4CF2BBEE.2050808@nachtgeist.net","subject":"Re: gitweb: false base href sent when integrated via reverse proxy and path_info is active","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2010-11-28T21:07:01Z","receivedAt":"2010-11-28T21:07:01Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"On Sun, 28 Nov 2010, Daniel Reichelt wrote:\n\n>>> Lacking that, a plain\n>>>\n>>> our $base_url  = 'whatever';\n>>>\n>>> in the gitweb config should probably work\n> \n> Nope again, I'm afraid it doesn't (see further down)\n\nStrange, it works for me (see below). \n \n>> See also gitweb/README, the \"Gitweb config file variables\" section:\n>> \n>>  * $base_url\n>>    Base URL for relative URLs in pages generated by gitweb,\n>>    (e.g. $logo, $favicon, @stylesheets if they are relative URLs),\n>>    needed and used only for URLs with nonempty PATH_INFO via\n>>    <base href=\"$base_url\">.  Usually gitweb sets its value correctly,\n>>                              ^^^^^^^\n>>    and there is no need to set this variable, e.g. to $my_uri or \"/\".\n>> \n>> The key word here is \"usually\" ;-)\n>> \n> \n> *oops* thank you all for the hint! I totally missed that.\n> \n> However, I just tried that and it failed. $base_url gets ignored in\n> gitweb.conf and even setting $my_url and $my_uri in gitweb.conf seems to\n> have no effect at all. For testing purposes I printed the relevant\n> variables to the html header:\n> \n> \n> gitweb.conf:\n> ************\n\nThe default name of gitweb config file is gitweb_config.perl, not \ngitweb.conf.  Are you sure you are picking correct config file?\n\n\n> our $feature{'pathinfo'}{'default'} = [1];\n> our $base_url = \"https://foobar\";\n> our $my_url = \"https://foo\";\n> our $my_uri = \"https://bar\";\n\nTry adding\n\n  our $site_name = \"foo\";\n\nto check if you are picking correct config file.\n\n> - git summary of repo \"test1\"\n> public url: https://sb74/projects/gitweb/test1/summary\n> revProxy url: https://localhost:446/projects/gitweb/test1/summary\n> ************\n> <head>\n> <meta http-equiv=\"content-type\" content=\"application/xhtml+xml; charset=utf-8\"/>\n> <meta name=\"generator\" content=\"gitweb/1.7.2.3 git/1.7.2.3\"/>\n> <meta name=\"robots\" content=\"index, nofollow\"/>\n> <title>localhost Git - test1/summary</title>\n> <base href=\"https://sb74:446/projects/gitweb\" />\n[...]\n> </head>\n\nI get the following when running with config file that contains:\n\n  our $version = \"current\";\n  [...]\n  our $site_name = \"[localhost]\";\n  [...]\n  our $base_url = \"https://localhost/gitweb/\";\n\n$ gitweb-run.sh \"\" \"/git.git\"\n  [...]\n  <head>\n  <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>\n  <meta name=\"generator\" content=\"gitweb/current git/1.7.3.2.171.g8ccd7\"/>\n  <meta name=\"robots\" content=\"index, nofollow\"/>\n  <title>[localhost] - git.git/summary</title>\n  <base href=\"https://localhost/gitweb/\" />\n  [...]\n\nSo it works for me.\n-- \nJakub Narebski\nPoland\n"},{"id":"156775","messageId":"20101128211054.GA20203@burratino","threadId":"25858","inReplyTo":"4CF2BBEE.2050808@nachtgeist.net","subject":"Re: gitweb: false base href sent when integrated via reverse proxy and path_info is active","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-11-28T21:10:55Z","receivedAt":"2010-11-28T21:10:55Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Daniel Reichelt wrote:\n\n> However, I just tried that and it failed. $base_url gets ignored in\n> gitweb.conf and even setting $my_url and $my_uri in gitweb.conf seems to\n> have no effect at all.\n\nAha.  The bug fixed by v1.7.3-rc0~85^2 (gitweb: allow configurations\nthat change with each request, 2010-07-30) strikes again.\n\nDaniel, could you try again with version 1:1.7.2.3-2.1 (from Debian sid)?\n\nJakub, we should probably tweak evaluate_uri to do something special if\n$base_url is already set, or advertise that $base_url needs to be set\nin per_request_config when that feature is enabled.\n\nThanks again.\nJonathan\n"},{"id":"156776","messageId":"4CF2C8E1.1050907@nachtgeist.net","threadId":"25858","inReplyTo":"201011282207.03261.jnareb@gmail.com","subject":"Re: gitweb: false base href sent when integrated via reverse proxy and path_info is active","fromName":"Daniel Reichelt","fromEmail":"debian@nachtgeist.net","sentAt":"2010-11-28T21:25:53Z","receivedAt":"2010-11-28T21:25:53Z","isPatch":false,"sender":{"key":"debian@nachtgeist.net","avatar":null},"body":"> The default name of gitweb config file is gitweb_config.perl, not\n> gitweb.conf.  Are you sure you are picking correct config file?\n\nSuppose this is Debian-specific:\n************\nour ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM);\nsub evaluate_gitweb_config {\n        our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || \"gitweb_config.perl\";\n        our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} ||\n\"/etc/gitweb.conf\";\n        # die if there are errors parsing config file\n        if (-e $GITWEB_CONFIG) {\n                do $GITWEB_CONFIG;\n                die $@ if $@;\n        } elsif (-e $GITWEB_CONFIG_SYSTEM) {\n                do $GITWEB_CONFIG_SYSTEM;\n                die $@ if $@;\n        }\n}\n************\n\n\n> Try adding\n>\n>   our $site_name = \"foo\";\n>\n> to check if you are picking correct config file.\n\nYap, $site_name shows up in my browser's title.\n"},{"id":"156777","messageId":"4CF2C999.4060601@nachtgeist.net","threadId":"25858","inReplyTo":"20101128211054.GA20203@burratino","subject":"Re: gitweb: false base href sent when integrated via reverse proxy and path_info is active","fromName":"Daniel Reichelt","fromEmail":"debian@nachtgeist.net","sentAt":"2010-11-28T21:28:57Z","receivedAt":"2010-11-28T21:28:57Z","isPatch":false,"sender":{"key":"debian@nachtgeist.net","avatar":null},"body":"> Aha.  The bug fixed by v1.7.3-rc0~85^2 (gitweb: allow configurations\n> that change with each request, 2010-07-30) strikes again.\n>\n> Daniel, could you try again with version 1:1.7.2.3-2.1 (from Debian sid)?\n\nYay - now setting $base_url in gitweb.conf works (and on a side note\n$my_url and $my_uri as well). Thanks to all of you guys for helping in\ntracking this down.\n\nCheers\nDaniel\n"},{"id":"156778","messageId":"201011282305.39975.jnareb@gmail.com","threadId":"25858","inReplyTo":"20101128211054.GA20203@burratino","subject":"Re: gitweb: false base href sent when integrated via reverse proxy and path_info is active","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2010-11-28T22:05:35Z","receivedAt":"2010-11-28T22:05:35Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"On Sun, 28 Nov 2010, Jonathan Nieder wrote:\n> Daniel Reichelt wrote:\n> \n> > However, I just tried that and it failed. $base_url gets ignored in\n> > gitweb.conf and even setting $my_url and $my_uri in gitweb.conf seems to\n> > have no effect at all.\n> \n> Aha.  The bug fixed by v1.7.3-rc0~85^2 (gitweb: allow configurations\n> that change with each request, 2010-07-30) strikes again.\n> \n> Daniel, could you try again with version 1:1.7.2.3-2.1 (from Debian sid)?\n> \n> Jakub, we should probably tweak evaluate_uri to do something special if\n> $base_url is already set, or advertise that $base_url needs to be set\n> in per_request_config when that feature is enabled.\n\nJonathan, something like this, perhaps?\n\n-- >8 ---- >8 --\nFrom: Jakub Narebski <jnareb@gmail.com>\nSubject: [PATCH/RFC] gitweb: Preserve $base_url if it was set\n\nIf $base_url was defined, then do not redefine it in evaluate_uri().\nThis matters only in the case when $base_url was set in gitweb config\nfile, and $per_request_config is false or is coderef; without this\nchange $base_url would get overwritten on subsequent requests from the\nvalue set in config.\n\nIf you need $base_url that can change with request, but the default\nvalue set by gitweb doesn't work for you, and you want most of gitweb\nconfig file to be evaluated only once, you need to use $per_request_config\ncoderef to set it.\n\nPossible-issue-reported-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nOn top of (gitweb: selectable configurations that change with each\nrequest, 2010-11-28).\n\n gitweb/gitweb.perl |   13 ++++++++-----\n 1 files changed, 8 insertions(+), 5 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 1d94718..5efee0d 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -36,10 +36,9 @@ sub evaluate_uri {\n \tour $my_url = $cgi->url();\n \tour $my_uri = $cgi->url(-absolute => 1);\n \n-\t# Base URL for relative URLs in gitweb ($logo, $favicon, ...),\n-\t# needed and used only for URLs with nonempty PATH_INFO\n-\tour $base_url = $my_url;\n-\n+\t# $base_url contains base URL for relative URLs in gitweb ($logo, $favicon, ...);\n+\t# it is needed and it is used only for URLs with nonempty PATH_INFO\n+\t#\n \t# When the script is used as DirectoryIndex, the URL does not contain the name\n \t# of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we\n \t# have to do it ourselves. We make $path_info global because it's also used\n@@ -57,7 +56,11 @@ sub evaluate_uri {\n \t\tif ($my_url =~ s,\\Q$path_info\\E$,, &&\n \t\t    $my_uri =~ s,\\Q$path_info\\E$,, &&\n \t\t    defined $ENV{'SCRIPT_NAME'}) {\n-\t\t\t$base_url = $cgi->url(-base => 1) . $ENV{'SCRIPT_NAME'};\n+\t\t\t# preserve existing $base_url\n+\t\t\t$base_url ||= $cgi->url(-base => 1) . $ENV{'SCRIPT_NAME'};\n+\t\t} else {\n+\t\t\t# in case e.g. $ENV{'SCRIPT_NAME'} is not defined\n+\t\t\t$base_url ||= $my_url;\n \t\t}\n \t}\n \n-- \n1.7.3\n"},{"id":"156787","messageId":"20101129001908.GA26358@burratino","threadId":"25858","inReplyTo":"201011282305.39975.jnareb@gmail.com","subject":"Re: [PATCH/RFC] gitweb: Preserve $base_url if it was set","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-11-29T00:19:08Z","receivedAt":"2010-11-29T00:19:08Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Jakub Narebski wrote:\n\n> If $base_url was defined, then do not redefine it in evaluate_uri().\n\nHow about $my_uri and $my_url?\n\nWhat happens if $ENV{PATH_INFO} or $cgi->url(...) changes between\nrequests?  This is partly my ignorance: perhaps FastCGI et al\nguarantee that such configuration changes can't happen within a single\nprocess?\n\nMaintaining backward compatibility while avoiding this last concern\nseems hard.  Since gitweb_config can contain something like\n\n\t$my_uri =~ s/foo/bar/;\n\none would want to populate $my_uri in advance.  Meanwhile, if the\ndefault for $my_uri could change between requests, we would want to be\nable to detect the case when $my_uri is not set.  But what if\ngitweb_config contains\n\n\t$my_uri = \"something\";\n\nwhere \"something\" happens to match the default value for $my_uri in\nthe first request?\n\nIt is tempting to change the documentation now and worry about code\nchanges later.  Something like this?\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\ndiff --git a/gitweb/README b/gitweb/README\nindex 6646fda..a9421e0 100644\n--- a/gitweb/README\n+++ b/gitweb/README\n@@ -177,13 +177,15 @@ not include variables usually directly set during build):\n  * $my_url, $my_uri\n    Full URL and absolute URL of gitweb script;\n    in earlier versions of gitweb you might have need to set those\n-   variables, now there should be no need to do it.\n+   variables, now there should be no need to do it.  See\n+   $per_request_config if you need to set them still.\n  * $base_url\n    Base URL for relative URLs in pages generated by gitweb,\n    (e.g. $logo, $favicon, @stylesheets if they are relative URLs),\n    needed and used only for URLs with nonempty PATH_INFO via\n    <base href=\"$base_url\">.  Usually gitweb sets its value correctly,\n    and there is no need to set this variable, e.g. to $my_uri or \"/\".\n+   See $per_request_config if you need to set it anyway.\n  * $home_link\n    Target of the home link on top of all pages (the first part of view\n    \"breadcrumbs\").  By default set to absolute URI of a page ($my_uri).\n@@ -252,7 +254,10 @@ not include variables usually directly set during build):\n      sub { $ENV{GL_USER} = $cgi->remote_user || \"gitweb\"; }\n    Otherwise it is treated as boolean value: if true gitweb would process\n    config file once per request, if false it would process config file only\n-   once.  The default is true.\n+   once.  Note: $my_url, $my_uri, and $base_url are overwritten with\n+   their default values before every request, so if you want to change\n+   them, be sure to set this variable to true or a code reference effecting\n+   the desired changes.  The default is true.\n \n Projects list file format\n ~~~~~~~~~~~~~~~~~~~~~~~~~\n"},{"id":"156786","messageId":"201011290151.14341.jnareb@gmail.com","threadId":"25858","inReplyTo":"20101129001908.GA26358@burratino","subject":"Re: [PATCH/RFC] gitweb/README: About $base_url etc. and $per_request_config","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2010-11-29T00:51:11Z","receivedAt":"2010-11-29T00:51:11Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Subject fixed.\n\nOn Mon, 29 Nov 2010, Jonathan Nieder wrote:\n> Jakub Narebski wrote:\n> \n> > If $base_url was defined, then do not redefine it in evaluate_uri().\n> \n> How about $my_uri and $my_url?\n> \n> What happens if $ENV{PATH_INFO} or $cgi->url(...) changes between\n> requests?  This is partly my ignorance: perhaps FastCGI et al\n> guarantee that such configuration changes can't happen within a single\n> process?\n\nI think that at least $ENV{PATH_INFO} can change with request, though\nI guess that $base_url should not change from request to request...\nthough there might be some corner cases.\n\n$my_uri and $my_url usually do change with each request...\n\n>\n> Maintaining backward compatibility while avoiding this last concern\n> seems hard.  Since gitweb_config can contain something like\n> \n> \t$my_uri =~ s/foo/bar/;\n> \n> one would want to populate $my_uri in advance.  Meanwhile, if the\n> default for $my_uri could change between requests, we would want to be\n> able to detect the case when $my_uri is not set.  But what if\n> gitweb_config contains\n> \n> \t$my_uri = \"something\";\n> \n> where \"something\" happens to match the default value for $my_uri in\n> the first request?\n> \n> It is tempting to change the documentation now and worry about code\n> changes later.  Something like this?\n> \n> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\n\n..therefore I think it is a better solution.\n\nAcked-by: Jakub Narebski <jnareb@gmail.com>\n\n> ---\n> diff --git a/gitweb/README b/gitweb/README\n> index 6646fda..a9421e0 100644\n> --- a/gitweb/README\n> +++ b/gitweb/README\n> @@ -177,13 +177,15 @@ not include variables usually directly set during build):\n>   * $my_url, $my_uri\n>     Full URL and absolute URL of gitweb script;\n>     in earlier versions of gitweb you might have need to set those\n> -   variables, now there should be no need to do it.\n> +   variables, now there should be no need to do it.  See\n> +   $per_request_config if you need to set them still.\n\nVery minor nitpick: perhaps it would be better to use\n\n      variables, now there should be no need to do it.\n  +   See $per_request_config if you need to set them still.\n\n\n>   * $base_url\n>     Base URL for relative URLs in pages generated by gitweb,\n>     (e.g. $logo, $favicon, @stylesheets if they are relative URLs),\n>     needed and used only for URLs with nonempty PATH_INFO via\n>     <base href=\"$base_url\">.  Usually gitweb sets its value correctly,\n>     and there is no need to set this variable, e.g. to $my_uri or \"/\".\n> +   See $per_request_config if you need to set it anyway.\n>   * $home_link\n>     Target of the home link on top of all pages (the first part of view\n>     \"breadcrumbs\").  By default set to absolute URI of a page ($my_uri).\n> @@ -252,7 +254,10 @@ not include variables usually directly set during build):\n>       sub { $ENV{GL_USER} = $cgi->remote_user || \"gitweb\"; }\n>     Otherwise it is treated as boolean value: if true gitweb would process\n>     config file once per request, if false it would process config file only\n> -   once.  The default is true.\n> +   once.  Note: $my_url, $my_uri, and $base_url are overwritten with\n> +   their default values before every request, so if you want to change\n> +   them, be sure to set this variable to true or a code reference effecting\n> +   the desired changes.  The default is true. \n\nPerhaps:\n\n      once.  The default is true.\n  +   Note: $my_url, $my_uri, and $base_url are overwritten with\n  +   their default values before every request, so if you want to change\n  +   them, be sure to set this variable to true or a code reference effecting\n  +   the desired changes.\n  \n\n-- \nJakub Narebski\nPoland\n"},{"id":"156822","messageId":"7vr5e457y6.fsf@alter.siamese.dyndns.org","threadId":"25858","inReplyTo":"20101129001908.GA26358@burratino","subject":"Re: [PATCH/RFC] gitweb: Preserve $base_url if it was set","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-11-29T17:57:21Z","receivedAt":"2010-11-29T17:57:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonathan Nieder <jrnieder@gmail.com> writes:\n\n> Jakub Narebski wrote:\n>\n>> If $base_url was defined, then do not redefine it in evaluate_uri().\n>\n> How about $my_uri and $my_url?\n>\n> What happens if $ENV{PATH_INFO} or $cgi->url(...) changes between\n> requests?  This is partly my ignorance: perhaps FastCGI et al\n> guarantee that such configuration changes can't happen within a single\n> process?\n>\n> Maintaining backward compatibility while avoiding this last concern\n> seems hard....\n> It is tempting to change the documentation now and worry about code\n> changes later.  Something like this?\n>\n> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\n\nSounds like a sensible thing to do; narrows an interface with two\nvariables into a more flexible new interface with a single variable.\n\n> ---\n> diff --git a/gitweb/README b/gitweb/README\n> index 6646fda..a9421e0 100644\n> --- a/gitweb/README\n> +++ b/gitweb/README\n> @@ -177,13 +177,15 @@ not include variables usually directly set during build):\n>   * $my_url, $my_uri\n>     Full URL and absolute URL of gitweb script;\n>     in earlier versions of gitweb you might have need to set those\n> -   variables, now there should be no need to do it.\n> +   variables, now there should be no need to do it.  See\n> +   $per_request_config if you need to set them still.\n>   * $base_url\n>     Base URL for relative URLs in pages generated by gitweb,\n>     (e.g. $logo, $favicon, @stylesheets if they are relative URLs),\n>     needed and used only for URLs with nonempty PATH_INFO via\n>     <base href=\"$base_url\">.  Usually gitweb sets its value correctly,\n>     and there is no need to set this variable, e.g. to $my_uri or \"/\".\n> +   See $per_request_config if you need to set it anyway.\n>   * $home_link\n>     Target of the home link on top of all pages (the first part of view\n>     \"breadcrumbs\").  By default set to absolute URI of a page ($my_uri).\n> @@ -252,7 +254,10 @@ not include variables usually directly set during build):\n>       sub { $ENV{GL_USER} = $cgi->remote_user || \"gitweb\"; }\n>     Otherwise it is treated as boolean value: if true gitweb would process\n>     config file once per request, if false it would process config file only\n> -   once.  The default is true.\n> +   once.  Note: $my_url, $my_uri, and $base_url are overwritten with\n> +   their default values before every request, so if you want to change\n> +   them, be sure to set this variable to true or a code reference effecting\n> +   the desired changes.  The default is true.\n>  \n>  Projects list file format\n>  ~~~~~~~~~~~~~~~~~~~~~~~~~\n"},{"id":"156898","messageId":"201011301922.11695.jnareb@gmail.com","threadId":"25858","inReplyTo":"20101128181215.GB19545@burratino","subject":"Re: gitweb: false base href sent when integrated via reverse proxy and path_info is active","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2010-11-30T18:22:09Z","receivedAt":"2010-11-30T18:22:09Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"On Sun, 28 Nov 2010, Jonathan Nieder wrote:\n> Jakub Narebski wrote:\n> \n> > See also gitweb/README, the \"Gitweb config file variables\" section:\n> > \n> >  * $base_url\n> >    Base URL for relative URLs in pages generated by gitweb,\n> >    (e.g. $logo, $favicon, @stylesheets if they are relative URLs),\n> >    needed and used only for URLs with nonempty PATH_INFO via\n> >    <base href=\"$base_url\">.  Usually gitweb sets its value correctly,\n> >                              ^^^^^^^\n> >    and there is no need to set this variable, e.g. to $my_uri or \"/\".\n> > \n> > The key word here is \"usually\" ;-)\n> \n> Thanks, all.  That helps.\n> \n> No time for it at the moment, but I'm taking this as evidence that\n> we need a gitweb.conf(5) manual page. :)  Would you be interested\n> in such a thing (as POD or asciidoc)?\n\nWell, both git-gui and gitk have their documentation in Documentation/\n(in AsciiDoc format), so perhaps it is time to add Documentation/gitweb.txt\nand possibly also Documentation/gitweb_config.txt (or gitweb.conf.txt).\n\nWith exception of t/README, the gitweb/README file is largest, with around\n570 lines, while next largest is (discarding also git-gui/po/README) main\nREADME file with around 50 lines.\n-- \nJakub Narebski\nPoland\n"},{"id":"156906","messageId":"7v8w0aw4x5.fsf@alter.siamese.dyndns.org","threadId":"25858","inReplyTo":"201011301922.11695.jnareb@gmail.com","subject":"Re: gitweb: false base href sent when integrated via reverse proxy and path_info is active","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-12-01T03:25:10Z","receivedAt":"2010-12-01T03:25:10Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jakub Narebski <jnareb@gmail.com> writes:\n\n> Well, both git-gui and gitk have their documentation in Documentation/\n> (in AsciiDoc format), so perhaps it is time to add Documentation/gitweb.txt\n> and possibly also Documentation/gitweb_config.txt (or gitweb.conf.txt).\n\nThat indeed sounds like a good idea to me.\n"}]}