| 1460 | } |
| 1461 | |
| 1462 | static int stateless_connect(const char *service_name) |
| 1463 | { |
| 1464 | struct discovery *discover; |
| 1465 | struct rpc_state rpc = RPC_STATE_INIT; |
| 1466 | struct strbuf buf = STRBUF_INIT; |
| 1467 | const char *accept_language; |
| 1468 | |
| 1469 | /* |
| 1470 | * Run the info/refs request and see if the server supports protocol |
| 1471 | * v2. If and only if the server supports v2 can we successfully |
| 1472 | * establish a stateless connection, otherwise we need to tell the |
| 1473 | * client to fallback to using other transport helper functions to |
| 1474 | * complete their request. |
| 1475 | * |
| 1476 | * The "git-upload-archive" service is a read-only operation. Fallback |
| 1477 | * to use "git-upload-pack" service to discover protocol version. |
| 1478 | */ |
| 1479 | if (!strcmp(service_name, "git-upload-archive")) |
| 1480 | discover = discover_refs("git-upload-pack", 0); |
| 1481 | else |
| 1482 | discover = discover_refs(service_name, 0); |
| 1483 | if (discover->version != protocol_v2) { |
| 1484 | printf("fallback\n"); |
| 1485 | fflush(stdout); |
| 1486 | return -1; |
| 1487 | } else { |
| 1488 | /* Stateless Connection established */ |
| 1489 | printf("\n"); |
| 1490 | fflush(stdout); |
| 1491 | } |
| 1492 | accept_language = http_get_accept_language_header(); |
| 1493 | if (accept_language) |
| 1494 | rpc.hdr_accept_language = xstrfmt("%s", accept_language); |
| 1495 | |
| 1496 | rpc.service_name = service_name; |
| 1497 | rpc.service_url = xstrfmt("%s%s", url.buf, rpc.service_name); |
| 1498 | rpc.hdr_content_type = xstrfmt("Content-Type: application/x-%s-request", rpc.service_name); |
| 1499 | rpc.hdr_accept = xstrfmt("Accept: application/x-%s-result", rpc.service_name); |
| 1500 | if (get_protocol_http_header(discover->version, &buf)) { |
| 1501 | rpc.protocol_header = strbuf_detach(&buf, NULL); |
| 1502 | } else { |
| 1503 | rpc.protocol_header = NULL; |
| 1504 | strbuf_release(&buf); |
| 1505 | } |
| 1506 | rpc.buf = xmalloc(http_post_buffer); |
| 1507 | rpc.alloc = http_post_buffer; |
| 1508 | rpc.len = 0; |
| 1509 | rpc.pos = 0; |
| 1510 | rpc.in = 1; |
| 1511 | rpc.out = 0; |
| 1512 | rpc.any_written = 0; |
| 1513 | rpc.gzip_request = 1; |
| 1514 | rpc.initial_buffer = 0; |
| 1515 | rpc.write_line_lengths = 1; |
| 1516 | rpc.flush_read_but_not_sent = 0; |
| 1517 | |
| 1518 | /* |
| 1519 | * Dump the capability listing that we got from the server earlier |
no test coverage detected