MCPcopy Index your code
hub / github.com/git/git / check_smart_http

Function check_smart_http

remote-curl.c:410–463  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

408}
409
410static void check_smart_http(struct discovery *d, const char *service,
411 struct strbuf *type)
412{
413 const char *p;
414 struct packet_reader reader;
415
416 /*
417 * If we don't see x-$service-advertisement, then it's not smart-http.
418 * But once we do, we commit to it and assume any other protocol
419 * violations are hard errors.
420 */
421 if (!skip_prefix(type->buf, "application/x-", &p) ||
422 !skip_prefix(p, service, &p) ||
423 strcmp(p, "-advertisement"))
424 return;
425
426 packet_reader_init(&reader, -1, d->buf, d->len,
427 PACKET_READ_CHOMP_NEWLINE |
428 PACKET_READ_DIE_ON_ERR_PACKET);
429 if (packet_reader_read(&reader) != PACKET_READ_NORMAL)
430 die(_("invalid server response; expected service, got flush packet"));
431
432 if (skip_prefix(reader.line, "# service=", &p) && !strcmp(p, service)) {
433 /*
434 * The header can include additional metadata lines, up
435 * until a packet flush marker. Ignore these now, but
436 * in the future we might start to scan them.
437 */
438 for (;;) {
439 packet_reader_read(&reader);
440 if (reader.pktlen <= 0) {
441 break;
442 }
443 }
444
445 /*
446 * v0 smart http; callers expect us to soak up the
447 * service and header packets
448 */
449 d->buf = reader.src_buffer;
450 d->len = reader.src_len;
451 d->proto_git = 1;
452
453 } else if (!strcmp(reader.line, "version 2")) {
454 /*
455 * v2 smart http; do not consume version packet, which will
456 * be handled elsewhere.
457 */
458 d->proto_git = 1;
459
460 } else {
461 die(_("invalid server response; got '%s'"), reader.line);
462 }
463}
464
465static struct discovery *discover_refs(const char *service, int for_push)
466{

Callers 1

discover_refsFunction · 0.85

Calls 3

packet_reader_initFunction · 0.85
packet_reader_readFunction · 0.85
dieFunction · 0.70

Tested by

no test coverage detected