Merge branch 'gc/config-context'
[alt-git.git] / http-backend.c
blobe1969c05dc658ed78274f3616df72c8d5bd2bfd5
1 #include "git-compat-util.h"
2 #include "alloc.h"
3 #include "config.h"
4 #include "environment.h"
5 #include "git-zlib.h"
6 #include "hex.h"
7 #include "path.h"
8 #include "repository.h"
9 #include "refs.h"
10 #include "pkt-line.h"
11 #include "object.h"
12 #include "tag.h"
13 #include "exec-cmd.h"
14 #include "run-command.h"
15 #include "string-list.h"
16 #include "url.h"
17 #include "strvec.h"
18 #include "packfile.h"
19 #include "object-store-ll.h"
20 #include "protocol.h"
21 #include "date.h"
22 #include "wrapper.h"
23 #include "write-or-die.h"
25 static const char content_type[] = "Content-Type";
26 static const char content_length[] = "Content-Length";
27 static const char last_modified[] = "Last-Modified";
28 static int getanyfile = 1;
29 static unsigned long max_request_buffer = 10 * 1024 * 1024;
31 static struct string_list *query_params;
33 struct rpc_service {
34 const char *name;
35 const char *config_name;
36 unsigned buffer_input : 1;
37 signed enabled : 2;
40 static struct rpc_service rpc_service[] = {
41 { "upload-pack", "uploadpack", 1, 1 },
42 { "receive-pack", "receivepack", 0, -1 },
45 static struct string_list *get_parameters(void)
47 if (!query_params) {
48 const char *query = getenv("QUERY_STRING");
50 CALLOC_ARRAY(query_params, 1);
51 while (query && *query) {
52 char *name = url_decode_parameter_name(&query);
53 char *value = url_decode_parameter_value(&query);
54 struct string_list_item *i;
56 i = string_list_lookup(query_params, name);
57 if (!i)
58 i = string_list_insert(query_params, name);
59 else
60 free(i->util);
61 i->util = value;
64 return query_params;
67 static const char *get_parameter(const char *name)
69 struct string_list_item *i;
70 i = string_list_lookup(get_parameters(), name);
71 return i ? i->util : NULL;
74 __attribute__((format (printf, 2, 3)))
75 static void format_write(int fd, const char *fmt, ...)
77 static char buffer[1024];
79 va_list args;
80 unsigned n;
82 va_start(args, fmt);
83 n = vsnprintf(buffer, sizeof(buffer), fmt, args);
84 va_end(args);
85 if (n >= sizeof(buffer))
86 die("protocol error: impossibly long line");
88 write_or_die(fd, buffer, n);
91 static void http_status(struct strbuf *hdr, unsigned code, const char *msg)
93 strbuf_addf(hdr, "Status: %u %s\r\n", code, msg);
96 static void hdr_str(struct strbuf *hdr, const char *name, const char *value)
98 strbuf_addf(hdr, "%s: %s\r\n", name, value);
101 static void hdr_int(struct strbuf *hdr, const char *name, uintmax_t value)
103 strbuf_addf(hdr, "%s: %" PRIuMAX "\r\n", name, value);
106 static void hdr_date(struct strbuf *hdr, const char *name, timestamp_t when)
108 const char *value = show_date(when, 0, DATE_MODE(RFC2822));
109 hdr_str(hdr, name, value);
112 static void hdr_nocache(struct strbuf *hdr)
114 hdr_str(hdr, "Expires", "Fri, 01 Jan 1980 00:00:00 GMT");
115 hdr_str(hdr, "Pragma", "no-cache");
116 hdr_str(hdr, "Cache-Control", "no-cache, max-age=0, must-revalidate");
119 static void hdr_cache_forever(struct strbuf *hdr)
121 timestamp_t now = time(NULL);
122 hdr_date(hdr, "Date", now);
123 hdr_date(hdr, "Expires", now + 31536000);
124 hdr_str(hdr, "Cache-Control", "public, max-age=31536000");
127 static void end_headers(struct strbuf *hdr)
129 strbuf_add(hdr, "\r\n", 2);
130 write_or_die(1, hdr->buf, hdr->len);
131 strbuf_release(hdr);
134 __attribute__((format (printf, 2, 3)))
135 static NORETURN void not_found(struct strbuf *hdr, const char *err, ...)
137 va_list params;
139 http_status(hdr, 404, "Not Found");
140 hdr_nocache(hdr);
141 end_headers(hdr);
143 va_start(params, err);
144 if (err && *err)
145 vfprintf(stderr, err, params);
146 va_end(params);
147 exit(0);
150 __attribute__((format (printf, 2, 3)))
151 static NORETURN void forbidden(struct strbuf *hdr, const char *err, ...)
153 va_list params;
155 http_status(hdr, 403, "Forbidden");
156 hdr_nocache(hdr);
157 end_headers(hdr);
159 va_start(params, err);
160 if (err && *err)
161 vfprintf(stderr, err, params);
162 va_end(params);
163 exit(0);
166 static void select_getanyfile(struct strbuf *hdr)
168 if (!getanyfile)
169 forbidden(hdr, "Unsupported service: getanyfile");
172 static void send_strbuf(struct strbuf *hdr,
173 const char *type, struct strbuf *buf)
175 hdr_int(hdr, content_length, buf->len);
176 hdr_str(hdr, content_type, type);
177 end_headers(hdr);
178 write_or_die(1, buf->buf, buf->len);
181 static void send_local_file(struct strbuf *hdr, const char *the_type,
182 const char *name)
184 char *p = git_pathdup("%s", name);
185 size_t buf_alloc = 8192;
186 char *buf = xmalloc(buf_alloc);
187 int fd;
188 struct stat sb;
190 fd = open(p, O_RDONLY);
191 if (fd < 0)
192 not_found(hdr, "Cannot open '%s': %s", p, strerror(errno));
193 if (fstat(fd, &sb) < 0)
194 die_errno("Cannot stat '%s'", p);
196 hdr_int(hdr, content_length, sb.st_size);
197 hdr_str(hdr, content_type, the_type);
198 hdr_date(hdr, last_modified, sb.st_mtime);
199 end_headers(hdr);
201 for (;;) {
202 ssize_t n = xread(fd, buf, buf_alloc);
203 if (n < 0)
204 die_errno("Cannot read '%s'", p);
205 if (!n)
206 break;
207 write_or_die(1, buf, n);
209 close(fd);
210 free(buf);
211 free(p);
214 static void get_text_file(struct strbuf *hdr, char *name)
216 select_getanyfile(hdr);
217 hdr_nocache(hdr);
218 send_local_file(hdr, "text/plain", name);
221 static void get_loose_object(struct strbuf *hdr, char *name)
223 select_getanyfile(hdr);
224 hdr_cache_forever(hdr);
225 send_local_file(hdr, "application/x-git-loose-object", name);
228 static void get_pack_file(struct strbuf *hdr, char *name)
230 select_getanyfile(hdr);
231 hdr_cache_forever(hdr);
232 send_local_file(hdr, "application/x-git-packed-objects", name);
235 static void get_idx_file(struct strbuf *hdr, char *name)
237 select_getanyfile(hdr);
238 hdr_cache_forever(hdr);
239 send_local_file(hdr, "application/x-git-packed-objects-toc", name);
242 static void http_config(void)
244 int i, value = 0;
245 struct strbuf var = STRBUF_INIT;
247 git_config_get_bool("http.getanyfile", &getanyfile);
248 git_config_get_ulong("http.maxrequestbuffer", &max_request_buffer);
250 for (i = 0; i < ARRAY_SIZE(rpc_service); i++) {
251 struct rpc_service *svc = &rpc_service[i];
252 strbuf_addf(&var, "http.%s", svc->config_name);
253 if (!git_config_get_bool(var.buf, &value))
254 svc->enabled = value;
255 strbuf_reset(&var);
258 strbuf_release(&var);
261 static struct rpc_service *select_service(struct strbuf *hdr, const char *name)
263 const char *svc_name;
264 struct rpc_service *svc = NULL;
265 int i;
267 if (!skip_prefix(name, "git-", &svc_name))
268 forbidden(hdr, "Unsupported service: '%s'", name);
270 for (i = 0; i < ARRAY_SIZE(rpc_service); i++) {
271 struct rpc_service *s = &rpc_service[i];
272 if (!strcmp(s->name, svc_name)) {
273 svc = s;
274 break;
278 if (!svc)
279 forbidden(hdr, "Unsupported service: '%s'", name);
281 if (svc->enabled < 0) {
282 const char *user = getenv("REMOTE_USER");
283 svc->enabled = (user && *user) ? 1 : 0;
285 if (!svc->enabled)
286 forbidden(hdr, "Service not enabled: '%s'", svc->name);
287 return svc;
290 static void write_to_child(int out, const unsigned char *buf, ssize_t len, const char *prog_name)
292 if (write_in_full(out, buf, len) < 0)
293 die("unable to write to '%s'", prog_name);
297 * This is basically strbuf_read(), except that if we
298 * hit max_request_buffer we die (we'd rather reject a
299 * maliciously large request than chew up infinite memory).
301 static ssize_t read_request_eof(int fd, unsigned char **out)
303 size_t len = 0, alloc = 8192;
304 unsigned char *buf = xmalloc(alloc);
306 if (max_request_buffer < alloc)
307 max_request_buffer = alloc;
309 while (1) {
310 ssize_t cnt;
312 cnt = read_in_full(fd, buf + len, alloc - len);
313 if (cnt < 0) {
314 free(buf);
315 return -1;
318 /* partial read from read_in_full means we hit EOF */
319 len += cnt;
320 if (len < alloc) {
321 *out = buf;
322 return len;
325 /* otherwise, grow and try again (if we can) */
326 if (alloc == max_request_buffer)
327 die("request was larger than our maximum size (%lu);"
328 " try setting GIT_HTTP_MAX_REQUEST_BUFFER",
329 max_request_buffer);
331 alloc = alloc_nr(alloc);
332 if (alloc > max_request_buffer)
333 alloc = max_request_buffer;
334 REALLOC_ARRAY(buf, alloc);
338 static ssize_t read_request_fixed_len(int fd, ssize_t req_len, unsigned char **out)
340 unsigned char *buf = NULL;
341 ssize_t cnt = 0;
343 if (max_request_buffer < req_len) {
344 die("request was larger than our maximum size (%lu): "
345 "%" PRIuMAX "; try setting GIT_HTTP_MAX_REQUEST_BUFFER",
346 max_request_buffer, (uintmax_t)req_len);
349 buf = xmalloc(req_len);
350 cnt = read_in_full(fd, buf, req_len);
351 if (cnt < 0) {
352 free(buf);
353 return -1;
355 *out = buf;
356 return cnt;
359 static ssize_t get_content_length(void)
361 ssize_t val = -1;
362 const char *str = getenv("CONTENT_LENGTH");
364 if (str && *str && !git_parse_ssize_t(str, &val))
365 die("failed to parse CONTENT_LENGTH: %s", str);
366 return val;
369 static ssize_t read_request(int fd, unsigned char **out, ssize_t req_len)
371 if (req_len < 0)
372 return read_request_eof(fd, out);
373 else
374 return read_request_fixed_len(fd, req_len, out);
377 static void inflate_request(const char *prog_name, int out, int buffer_input, ssize_t req_len)
379 git_zstream stream;
380 unsigned char *full_request = NULL;
381 unsigned char in_buf[8192];
382 unsigned char out_buf[8192];
383 unsigned long cnt = 0;
384 int req_len_defined = req_len >= 0;
385 size_t req_remaining_len = req_len;
387 memset(&stream, 0, sizeof(stream));
388 git_inflate_init_gzip_only(&stream);
390 while (1) {
391 ssize_t n;
393 if (buffer_input) {
394 if (full_request)
395 n = 0; /* nothing left to read */
396 else
397 n = read_request(0, &full_request, req_len);
398 stream.next_in = full_request;
399 } else {
400 ssize_t buffer_len;
401 if (req_len_defined && req_remaining_len <= sizeof(in_buf))
402 buffer_len = req_remaining_len;
403 else
404 buffer_len = sizeof(in_buf);
405 n = xread(0, in_buf, buffer_len);
406 stream.next_in = in_buf;
407 if (req_len_defined && n > 0)
408 req_remaining_len -= n;
411 if (n <= 0)
412 die("request ended in the middle of the gzip stream");
413 stream.avail_in = n;
415 while (0 < stream.avail_in) {
416 int ret;
418 stream.next_out = out_buf;
419 stream.avail_out = sizeof(out_buf);
421 ret = git_inflate(&stream, Z_NO_FLUSH);
422 if (ret != Z_OK && ret != Z_STREAM_END)
423 die("zlib error inflating request, result %d", ret);
425 n = stream.total_out - cnt;
426 write_to_child(out, out_buf, stream.total_out - cnt, prog_name);
427 cnt = stream.total_out;
429 if (ret == Z_STREAM_END)
430 goto done;
434 done:
435 git_inflate_end(&stream);
436 close(out);
437 free(full_request);
440 static void copy_request(const char *prog_name, int out, ssize_t req_len)
442 unsigned char *buf;
443 ssize_t n = read_request(0, &buf, req_len);
444 if (n < 0)
445 die_errno("error reading request body");
446 write_to_child(out, buf, n, prog_name);
447 close(out);
448 free(buf);
451 static void pipe_fixed_length(const char *prog_name, int out, size_t req_len)
453 unsigned char buf[8192];
454 size_t remaining_len = req_len;
456 while (remaining_len > 0) {
457 size_t chunk_length = remaining_len > sizeof(buf) ? sizeof(buf) : remaining_len;
458 ssize_t n = xread(0, buf, chunk_length);
459 if (n < 0)
460 die_errno("Reading request failed");
461 write_to_child(out, buf, n, prog_name);
462 remaining_len -= n;
465 close(out);
468 static void run_service(const char **argv, int buffer_input)
470 const char *encoding = getenv("HTTP_CONTENT_ENCODING");
471 const char *user = getenv("REMOTE_USER");
472 const char *host = getenv("REMOTE_ADDR");
473 int gzipped_request = 0;
474 struct child_process cld = CHILD_PROCESS_INIT;
475 ssize_t req_len = get_content_length();
477 if (encoding && (!strcmp(encoding, "gzip") || !strcmp(encoding, "x-gzip")))
478 gzipped_request = 1;
480 if (!user || !*user)
481 user = "anonymous";
482 if (!host || !*host)
483 host = "(none)";
485 if (!getenv("GIT_COMMITTER_NAME"))
486 strvec_pushf(&cld.env, "GIT_COMMITTER_NAME=%s", user);
487 if (!getenv("GIT_COMMITTER_EMAIL"))
488 strvec_pushf(&cld.env,
489 "GIT_COMMITTER_EMAIL=%s@http.%s", user, host);
491 strvec_pushv(&cld.args, argv);
492 if (buffer_input || gzipped_request || req_len >= 0)
493 cld.in = -1;
494 cld.git_cmd = 1;
495 cld.clean_on_exit = 1;
496 cld.wait_after_clean = 1;
497 if (start_command(&cld))
498 exit(1);
500 close(1);
501 if (gzipped_request)
502 inflate_request(argv[0], cld.in, buffer_input, req_len);
503 else if (buffer_input)
504 copy_request(argv[0], cld.in, req_len);
505 else if (req_len >= 0)
506 pipe_fixed_length(argv[0], cld.in, req_len);
507 else
508 close(0);
510 if (finish_command(&cld))
511 exit(1);
514 static int show_text_ref(const char *name, const struct object_id *oid,
515 int flag UNUSED, void *cb_data)
517 const char *name_nons = strip_namespace(name);
518 struct strbuf *buf = cb_data;
519 struct object *o = parse_object(the_repository, oid);
520 if (!o)
521 return 0;
523 strbuf_addf(buf, "%s\t%s\n", oid_to_hex(oid), name_nons);
524 if (o->type == OBJ_TAG) {
525 o = deref_tag(the_repository, o, name, 0);
526 if (!o)
527 return 0;
528 strbuf_addf(buf, "%s\t%s^{}\n", oid_to_hex(&o->oid),
529 name_nons);
531 return 0;
534 static void get_info_refs(struct strbuf *hdr, char *arg UNUSED)
536 const char *service_name = get_parameter("service");
537 struct strbuf buf = STRBUF_INIT;
539 hdr_nocache(hdr);
541 if (service_name) {
542 const char *argv[] = {NULL /* service name */,
543 "--http-backend-info-refs",
544 ".", NULL};
545 struct rpc_service *svc = select_service(hdr, service_name);
547 strbuf_addf(&buf, "application/x-git-%s-advertisement",
548 svc->name);
549 hdr_str(hdr, content_type, buf.buf);
550 end_headers(hdr);
553 if (determine_protocol_version_server() != protocol_v2) {
554 packet_write_fmt(1, "# service=git-%s\n", svc->name);
555 packet_flush(1);
558 argv[0] = svc->name;
559 run_service(argv, 0);
561 } else {
562 select_getanyfile(hdr);
563 for_each_namespaced_ref(show_text_ref, &buf);
564 send_strbuf(hdr, "text/plain", &buf);
566 strbuf_release(&buf);
569 static int show_head_ref(const char *refname, const struct object_id *oid,
570 int flag, void *cb_data)
572 struct strbuf *buf = cb_data;
574 if (flag & REF_ISSYMREF) {
575 const char *target = resolve_ref_unsafe(refname,
576 RESOLVE_REF_READING,
577 NULL, NULL);
579 if (target)
580 strbuf_addf(buf, "ref: %s\n", strip_namespace(target));
581 } else {
582 strbuf_addf(buf, "%s\n", oid_to_hex(oid));
585 return 0;
588 static void get_head(struct strbuf *hdr, char *arg UNUSED)
590 struct strbuf buf = STRBUF_INIT;
592 select_getanyfile(hdr);
593 head_ref_namespaced(show_head_ref, &buf);
594 send_strbuf(hdr, "text/plain", &buf);
595 strbuf_release(&buf);
598 static void get_info_packs(struct strbuf *hdr, char *arg UNUSED)
600 size_t objdirlen = strlen(get_object_directory());
601 struct strbuf buf = STRBUF_INIT;
602 struct packed_git *p;
603 size_t cnt = 0;
605 select_getanyfile(hdr);
606 for (p = get_all_packs(the_repository); p; p = p->next) {
607 if (p->pack_local)
608 cnt++;
611 strbuf_grow(&buf, cnt * 53 + 2);
612 for (p = get_all_packs(the_repository); p; p = p->next) {
613 if (p->pack_local)
614 strbuf_addf(&buf, "P %s\n", p->pack_name + objdirlen + 6);
616 strbuf_addch(&buf, '\n');
618 hdr_nocache(hdr);
619 send_strbuf(hdr, "text/plain; charset=utf-8", &buf);
620 strbuf_release(&buf);
623 static void check_content_type(struct strbuf *hdr, const char *accepted_type)
625 const char *actual_type = getenv("CONTENT_TYPE");
627 if (!actual_type)
628 actual_type = "";
630 if (strcmp(actual_type, accepted_type)) {
631 http_status(hdr, 415, "Unsupported Media Type");
632 hdr_nocache(hdr);
633 end_headers(hdr);
634 format_write(1,
635 "Expected POST with Content-Type '%s',"
636 " but received '%s' instead.\n",
637 accepted_type, actual_type);
638 exit(0);
642 static void service_rpc(struct strbuf *hdr, char *service_name)
644 const char *argv[] = {NULL, "--stateless-rpc", ".", NULL};
645 struct rpc_service *svc = select_service(hdr, service_name);
646 struct strbuf buf = STRBUF_INIT;
648 strbuf_reset(&buf);
649 strbuf_addf(&buf, "application/x-git-%s-request", svc->name);
650 check_content_type(hdr, buf.buf);
652 hdr_nocache(hdr);
654 strbuf_reset(&buf);
655 strbuf_addf(&buf, "application/x-git-%s-result", svc->name);
656 hdr_str(hdr, content_type, buf.buf);
658 end_headers(hdr);
660 argv[0] = svc->name;
661 run_service(argv, svc->buffer_input);
662 strbuf_release(&buf);
665 static int dead;
666 static NORETURN void die_webcgi(const char *err, va_list params)
668 if (dead <= 1) {
669 struct strbuf hdr = STRBUF_INIT;
670 report_fn die_message_fn = get_die_message_routine();
672 die_message_fn(err, params);
674 http_status(&hdr, 500, "Internal Server Error");
675 hdr_nocache(&hdr);
676 end_headers(&hdr);
678 exit(0); /* we successfully reported a failure ;-) */
681 static int die_webcgi_recursing(void)
683 return dead++ > 1;
686 static char* getdir(void)
688 struct strbuf buf = STRBUF_INIT;
689 char *pathinfo = getenv("PATH_INFO");
690 char *root = getenv("GIT_PROJECT_ROOT");
691 char *path = getenv("PATH_TRANSLATED");
693 if (root && *root) {
694 if (!pathinfo || !*pathinfo)
695 die("GIT_PROJECT_ROOT is set but PATH_INFO is not");
696 if (daemon_avoid_alias(pathinfo))
697 die("'%s': aliased", pathinfo);
698 end_url_with_slash(&buf, root);
699 if (pathinfo[0] == '/')
700 pathinfo++;
701 strbuf_addstr(&buf, pathinfo);
702 return strbuf_detach(&buf, NULL);
703 } else if (path && *path) {
704 return xstrdup(path);
705 } else
706 die("No GIT_PROJECT_ROOT or PATH_TRANSLATED from server");
707 return NULL;
710 static struct service_cmd {
711 const char *method;
712 const char *pattern;
713 void (*imp)(struct strbuf *, char *);
714 } services[] = {
715 {"GET", "/HEAD$", get_head},
716 {"GET", "/info/refs$", get_info_refs},
717 {"GET", "/objects/info/alternates$", get_text_file},
718 {"GET", "/objects/info/http-alternates$", get_text_file},
719 {"GET", "/objects/info/packs$", get_info_packs},
720 {"GET", "/objects/[0-9a-f]{2}/[0-9a-f]{38}$", get_loose_object},
721 {"GET", "/objects/[0-9a-f]{2}/[0-9a-f]{62}$", get_loose_object},
722 {"GET", "/objects/pack/pack-[0-9a-f]{40}\\.pack$", get_pack_file},
723 {"GET", "/objects/pack/pack-[0-9a-f]{64}\\.pack$", get_pack_file},
724 {"GET", "/objects/pack/pack-[0-9a-f]{40}\\.idx$", get_idx_file},
725 {"GET", "/objects/pack/pack-[0-9a-f]{64}\\.idx$", get_idx_file},
727 {"POST", "/git-upload-pack$", service_rpc},
728 {"POST", "/git-receive-pack$", service_rpc}
731 static int bad_request(struct strbuf *hdr, const struct service_cmd *c)
733 const char *proto = getenv("SERVER_PROTOCOL");
735 if (proto && !strcmp(proto, "HTTP/1.1")) {
736 http_status(hdr, 405, "Method Not Allowed");
737 hdr_str(hdr, "Allow",
738 !strcmp(c->method, "GET") ? "GET, HEAD" : c->method);
739 } else
740 http_status(hdr, 400, "Bad Request");
741 hdr_nocache(hdr);
742 end_headers(hdr);
743 return 0;
746 int cmd_main(int argc UNUSED, const char **argv UNUSED)
748 char *method = getenv("REQUEST_METHOD");
749 const char *proto_header;
750 char *dir;
751 struct service_cmd *cmd = NULL;
752 char *cmd_arg = NULL;
753 int i;
754 struct strbuf hdr = STRBUF_INIT;
756 set_die_routine(die_webcgi);
757 set_die_is_recursing_routine(die_webcgi_recursing);
759 if (!method)
760 die("No REQUEST_METHOD from server");
761 if (!strcmp(method, "HEAD"))
762 method = "GET";
763 dir = getdir();
765 for (i = 0; i < ARRAY_SIZE(services); i++) {
766 struct service_cmd *c = &services[i];
767 regex_t re;
768 regmatch_t out[1];
769 int ret;
771 if (regcomp(&re, c->pattern, REG_EXTENDED))
772 die("Bogus regex in service table: %s", c->pattern);
773 ret = regexec(&re, dir, 1, out, 0);
774 regfree(&re);
776 if (!ret) {
777 size_t n;
779 if (strcmp(method, c->method))
780 return bad_request(&hdr, c);
782 cmd = c;
783 n = out[0].rm_eo - out[0].rm_so;
784 cmd_arg = xmemdupz(dir + out[0].rm_so + 1, n - 1);
785 dir[out[0].rm_so] = 0;
786 break;
790 if (!cmd)
791 not_found(&hdr, "Request not supported: '%s'", dir);
793 setup_path();
794 if (!enter_repo(dir, 0))
795 not_found(&hdr, "Not a git repository: '%s'", dir);
796 if (!getenv("GIT_HTTP_EXPORT_ALL") &&
797 access("git-daemon-export-ok", F_OK) )
798 not_found(&hdr, "Repository not exported: '%s'", dir);
799 free(dir);
801 http_config();
802 max_request_buffer = git_env_ulong("GIT_HTTP_MAX_REQUEST_BUFFER",
803 max_request_buffer);
804 proto_header = getenv("HTTP_GIT_PROTOCOL");
805 if (proto_header)
806 setenv(GIT_PROTOCOL_ENVIRONMENT, proto_header, 0);
808 cmd->imp(&hdr, cmd_arg);
809 free(cmd_arg);
810 return 0;