Skip to content

Commit 0131e3e

Browse files
committed
test-gvfs-protocol: also serve smart protocol
This comes in handy, as we want to verify that `scalar clone` also works against a GVFS-enabled remote repository. Note that we have to set `MSYS2_ENV_CONV_EXCL` to prevent MSYS2 from mangling `PATH_TRANSLATED`: The value _does_ look like a Unix-style path, but no, MSYS2 must not be allowed to convert that into a Windows path: `http-backend` needs it in the unmodified form. (The MSYS2 runtime comes in when `git` is run via `bin-wrappers/git`, which is a shell script.) Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent a97f3d5 commit 0131e3e

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

t/helper/test-gvfs-protocol.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "git-compat-util.h"
22
#include "environment.h"
3+
#include "gettext.h"
34
#include "hex.h"
45
#include "alloc.h"
56
#include "setup.h"
@@ -1490,6 +1491,8 @@ static enum worker_result req__read(struct req *req, int fd)
14901491

14911492
static enum worker_result dispatch(struct req *req)
14921493
{
1494+
static regex_t *smart_http_regex;
1495+
static int initialized;
14931496
const char *method;
14941497
enum worker_result wr;
14951498

@@ -1538,6 +1541,53 @@ static enum worker_result dispatch(struct req *req)
15381541
return do__gvfs_prefetch__get(req);
15391542
}
15401543

1544+
if (!initialized) {
1545+
smart_http_regex = xmalloc(sizeof(*smart_http_regex));
1546+
if (regcomp(smart_http_regex, "^/(HEAD|info/refs|"
1547+
"objects/info/[^/]+|git-(upload|receive)-pack)$",
1548+
REG_EXTENDED)) {
1549+
warning("could not compile smart HTTP regex");
1550+
smart_http_regex = NULL;
1551+
}
1552+
initialized = 1;
1553+
}
1554+
1555+
if (smart_http_regex &&
1556+
!regexec(smart_http_regex, req->uri_base.buf, 0, NULL, 0)) {
1557+
const char *ok = "HTTP/1.1 200 OK\r\n";
1558+
struct child_process cp = CHILD_PROCESS_INIT;
1559+
int i, res;
1560+
1561+
if (write(1, ok, strlen(ok)) < 0)
1562+
return error(_("could not send '%s'"), ok);
1563+
1564+
strvec_pushf(&cp.env, "REQUEST_METHOD=%s", method);
1565+
strvec_pushf(&cp.env, "PATH_TRANSLATED=%s",
1566+
req->uri_base.buf);
1567+
/* Prevent MSYS2 from "converting to a Windows path" */
1568+
strvec_pushf(&cp.env,
1569+
"MSYS2_ENV_CONV_EXCL=PATH_TRANSLATED");
1570+
strvec_push(&cp.env, "SERVER_PROTOCOL=HTTP/1.1");
1571+
if (req->quest_args.len)
1572+
strvec_pushf(&cp.env, "QUERY_STRING=%s",
1573+
req->quest_args.buf);
1574+
for (i = 0; i < req->header_list.nr; i++) {
1575+
const char *header = req->header_list.items[i].string;
1576+
if (!strncasecmp("Content-Type: ", header, 14))
1577+
strvec_pushf(&cp.env, "CONTENT_TYPE=%s",
1578+
header + 14);
1579+
else if (!strncasecmp("Content-Length: ", header, 16))
1580+
strvec_pushf(&cp.env, "CONTENT_LENGTH=%s",
1581+
header + 16);
1582+
}
1583+
cp.git_cmd = 1;
1584+
strvec_push(&cp.args, "http-backend");
1585+
res = run_command(&cp);
1586+
close(1);
1587+
close(0);
1588+
return !!res;
1589+
}
1590+
15411591
return send_http_error(1, 501, "Not Implemented", -1,
15421592
WR_OK | WR_HANGUP);
15431593
}

0 commit comments

Comments
 (0)