git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org,
	Konstantin Ryabitsev <konstantin@linuxfoundation.org>,
	Philippe Blain <levraiphilippeblain@gmail.com>
Subject: [PATCH 2/5] http-backend: handle HTTP_GIT_PROTOCOL CGI variable
Date: Fri, 10 Sep 2021 10:05:45 -0400	[thread overview]
Message-ID: <YTtmOfCzvxYrBxso@coredump.intra.peff.net> (raw)
In-Reply-To: <YTtleYs48A1NpUpp@coredump.intra.peff.net>

When a client requests the v2 protocol over HTTP, they set the
Git-Protocol header. Webservers will generally make that available to
our CGI as HTTP_GIT_PROTOCOL in the environment. However, that's not
sufficient for upload-pack, etc, to respect it; they look in
GIT_PROTOCOL (without the HTTP_ prefix).

Either the webserver or the CGI is responsible for relaying that HTTP
header into the GIT_PROTOCOL variable. Traditionally, our tests have
configured the webserver to do so, but that's a burden on the server
admin. We can make this work out of the box by having the http-backend
CGI copy the contents of HTTP_GIT_PROTOCOL to GIT_PROTOCOL.

There are no new tests here. By removing the SetEnvIf line from our
test Apache config, we're now relying on this behavior of http-backend
to trigger the v2 protocol there (and there are numerous tests that fail
if this doesn't work).

There is one subtlety here: we copy HTTP_GIT_PROTOCOL only if there is
no existing GIT_PROTOCOL variable. That leaves the webserver admin free
to override the client's decision if they choose. This is unlikely to be
useful in practice, but is more flexible. And indeed, it allows the
v2-to-v0 fallback test added in the previous commit to continue working.

Signed-off-by: Jeff King <peff@peff.net>
---
 http-backend.c          | 4 ++++
 t/lib-httpd/apache.conf | 2 --
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/http-backend.c b/http-backend.c
index b329bf63f0..92ceb31f9a 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -739,6 +739,7 @@ static int bad_request(struct strbuf *hdr, const struct service_cmd *c)
 int cmd_main(int argc, const char **argv)
 {
 	char *method = getenv("REQUEST_METHOD");
+	const char *proto_header;
 	char *dir;
 	struct service_cmd *cmd = NULL;
 	char *cmd_arg = NULL;
@@ -789,6 +790,9 @@ int cmd_main(int argc, const char **argv)
 	http_config();
 	max_request_buffer = git_env_ulong("GIT_HTTP_MAX_REQUEST_BUFFER",
 					   max_request_buffer);
+	proto_header = getenv("HTTP_GIT_PROTOCOL");
+	if (proto_header)
+		setenv(GIT_PROTOCOL_ENVIRONMENT, proto_header, 0);
 
 	cmd->imp(&hdr, cmd_arg);
 	return 0;
diff --git a/t/lib-httpd/apache.conf b/t/lib-httpd/apache.conf
index 1321357d8b..180a41fe96 100644
--- a/t/lib-httpd/apache.conf
+++ b/t/lib-httpd/apache.conf
@@ -81,8 +81,6 @@ PassEnv GIT_TRACE
 PassEnv GIT_CONFIG_NOSYSTEM
 PassEnv GIT_TEST_SIDEBAND_ALL
 
-SetEnvIf Git-Protocol ".*" GIT_PROTOCOL=$0
-
 Alias /dumb/ www/
 Alias /auth/dumb/ www/auth/dumb/
 
-- 
2.33.0.731.g24eb83922d


  parent reply	other threads:[~2021-09-10 14:05 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-04 15:17 [PATCH] Docs: web server must setenv GIT_PROTOCOL for v2 Konstantin Ryabitsev
2021-09-04 15:55 ` Jeff King
2021-09-07 20:57   ` Junio C Hamano
2021-09-07 21:11   ` Konstantin Ryabitsev
2021-09-08 10:48     ` Jeff King
2021-09-08 10:57       ` Jeff King
2021-09-08 16:50         ` Eric Wong
2021-09-09 17:28         ` Junio C Hamano
2021-09-09 17:35           ` Junio C Hamano
2021-09-10 11:39             ` Jeff King
2021-09-10 14:02               ` Jeff King
2021-09-10 14:04                 ` [PATCH 1/5] t5551: test v2-to-v0 http protocol fallback Jeff King
2021-09-10 14:05                 ` Jeff King [this message]
2021-09-10 14:09                 ` [PATCH 3/5] docs/http-backend: mention v2 protocol Jeff King
2021-09-10 14:09                 ` [PATCH 4/5] docs/git: discuss server-side config for GIT_PROTOCOL Jeff King
2021-09-10 14:10                 ` [PATCH 5/5] docs/protocol-v2: point readers transport config discussion Jeff King
2021-09-10 22:08                 ` [PATCH] Docs: web server must setenv GIT_PROTOCOL for v2 Junio C Hamano
2021-09-09 17:50         ` Philippe Blain
2021-09-10  5:39           ` Junio C Hamano
2021-09-10 11:40             ` Jeff King

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=YTtmOfCzvxYrBxso@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=konstantin@linuxfoundation.org \
    --cc=levraiphilippeblain@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).