commit fd1b27119fe0bafd2e0b5ee26e877c742edfeb0e from: Stefan Sperling date: Tue Apr 16 12:48:27 2024 UTC log pkt lines read and written by got-fetch-http, in verbose mode commit - 3bdb50664480ef16bc57431ac739d4010133d2a2 commit + fd1b27119fe0bafd2e0b5ee26e877c742edfeb0e blob - 8d8ebb693f81dbed4045da8fa1c57f90b2e362a2 blob + 02951a4033a9780646d80ed187c221487167e497 --- libexec/got-fetch-http/got-fetch-http.c +++ libexec/got-fetch-http/got-fetch-http.c @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -217,7 +218,7 @@ http_parse_reply(struct bufio *bio, int *chunked, cons } if (verbose > 0) - fprintf(stderr, "%s: response: %s", getprogname(), line); + fprintf(stderr, "%s: response: %s\n", getprogname(), line); if ((cp = strchr(line, ' ')) == NULL) { warnx("malformed HTTP response"); @@ -363,6 +364,8 @@ get_refs(int https, const char *host, const char *port int chunked; int sock; int ret = -1; + int i, n; + long long t; if ((sock = dial(https, host, port)) == -1) return -1; @@ -413,7 +416,36 @@ get_refs(int https, const char *host, const char *port if (r == 0) break; + if (r < 4) + goto err; + fwrite(buf, 1, r, stdout); + + n = 0; + while (verbose && n + 4 < r) { + buf[n + 4] = '\0'; + t = hexstrtonum(&buf[n], 0, sizeof(buf) - n, &errstr); + if (errstr != NULL) { + warnx("pktline len is %s", errstr); + goto err; + } + + if (t < 6) { + warnx("pktline len is too small"); + goto err; + } + + fprintf(stderr, "%s: readpkt: %lld:\t", + getprogname(), t - 4); + for (i = 5; i < t; i++) { + if (isprint((unsigned char)buf[n + i])) + fputc(buf[n + i], stderr); + else + fprintf(stderr, "[0x%.2x]", buf[n + i]); + } + fputc('\n', stderr); + n += t; + } } fflush(stdout); @@ -489,6 +521,19 @@ upload_request(int https, const char *host, const char if (r != t - 4) goto err; + if (verbose) { + int i; + fprintf(stderr, "%s: writepkt: %.4x:\t", + getprogname(), (unsigned int)t); + for (i = 4; i < t; i++) { + if (isprint((unsigned char)buf[i])) + fputc(buf[i], stderr); + else + fprintf(stderr, "[0x%.2x]", buf[i]); + } + fputc('\n', stderr); + } + if (http_chunk(&bio, buf, t)) goto err; }