From: Eric Wong <normalperson@yhbt.net>
To: Lars Hjemli <hjemli@gmail.com>
Cc: git@vger.kernel.org
Subject: [cgit PATCH] use Host: header to generate cgit_hosturl
Date: Sun, 31 Aug 2008 23:30:33 -0700 [thread overview]
Message-ID: <20080901063033.GA21848@untitled> (raw)
I run an instance of lighttpd for cgit behind nginx (nginx
doesn't execute CGI). So the port (SERVER_PORT=33333) that
lighttpd runs on sends to cgit is different from the standard
port 80 that public clients connect to (via nginx).
This was causing the Atom feed URL to show the private port
number that lighttpd was running on.
Since the HTTP/1.1 "Host" header includes the port number if
running on a non-standard port, it allows non-client-facing HTTP
servers to transparently generate public URLs that clients can
see.
So use the "Host" header if it is available and fall back to
SERVER_NAME/SERVER_PORT for some clients that don't set
HTTP_HOST.
Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
ui-shared.c | 19 ++++++++++++-------
1 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/ui-shared.c b/ui-shared.c
index 37c60b2..5a848c1 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -38,14 +38,19 @@ char *cgit_hosturl()
{
char *host, *port;
- host = getenv("SERVER_NAME");
- if (!host)
- return NULL;
- port = getenv("SERVER_PORT");
- if (port && atoi(port) != 80)
- host = xstrdup(fmt("%s:%d", host, atoi(port)));
- else
+ host = getenv("HTTP_HOST");
+ if (host) {
host = xstrdup(host);
+ } else {
+ host = getenv("SERVER_NAME");
+ if (!host)
+ return NULL;
+ port = getenv("SERVER_PORT");
+ if (port && atoi(port) != 80)
+ host = xstrdup(fmt("%s:%d", host, atoi(port)));
+ else
+ host = xstrdup(host);
+ }
return host;
}
--
Eric Wong
next reply other threads:[~2008-09-01 6:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-01 6:30 Eric Wong [this message]
2008-09-01 20:36 ` [cgit PATCH] use Host: header to generate cgit_hosturl Lars Hjemli
2008-09-01 23:07 ` Eric Wong
2008-09-01 23:14 ` Lars Hjemli
2008-09-01 23:30 ` Eric Wong
2008-09-02 7:24 ` Lars Hjemli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080901063033.GA21848@untitled \
--to=normalperson@yhbt.net \
--cc=git@vger.kernel.org \
--cc=hjemli@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).