Skip to content

Commit ff6a37c

Browse files
peffgitster
authored andcommitted
http-backend: handle HTTP_GIT_PROTOCOL CGI variable
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2614698 commit ff6a37c

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

http-backend.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ static int bad_request(struct strbuf *hdr, const struct service_cmd *c)
739739
int cmd_main(int argc, const char **argv)
740740
{
741741
char *method = getenv("REQUEST_METHOD");
742+
const char *proto_header;
742743
char *dir;
743744
struct service_cmd *cmd = NULL;
744745
char *cmd_arg = NULL;
@@ -789,6 +790,9 @@ int cmd_main(int argc, const char **argv)
789790
http_config();
790791
max_request_buffer = git_env_ulong("GIT_HTTP_MAX_REQUEST_BUFFER",
791792
max_request_buffer);
793+
proto_header = getenv("HTTP_GIT_PROTOCOL");
794+
if (proto_header)
795+
setenv(GIT_PROTOCOL_ENVIRONMENT, proto_header, 0);
792796

793797
cmd->imp(&hdr, cmd_arg);
794798
return 0;

t/lib-httpd/apache.conf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ PassEnv GIT_TRACE
8181
PassEnv GIT_CONFIG_NOSYSTEM
8282
PassEnv GIT_TEST_SIDEBAND_ALL
8383

84-
SetEnvIf Git-Protocol ".*" GIT_PROTOCOL=$0
85-
8684
Alias /dumb/ www/
8785
Alias /auth/dumb/ www/auth/dumb/
8886

0 commit comments

Comments
 (0)