Subject: Re: [RFC 2/2] Add Git-aware CGI for Git-aware smart HTTP transport

From: "H. Peter Anvin" <[email-masked]>
Date: Sun, 03 Aug 2008 04:38:45 -0700

Shawn O. Pearce wrote:
> +#define hex(a) (hexchar[(a) & 15])
> +static void chunked_write(const char *fmt, ...)
> +{
> +	static const char hexchar[] = "0123456789abcdef";
> +	va_list args;
> +	unsigned n;
> +
> +	va_start(args, fmt);
> +	n = vsnprintf(buffer + 6, sizeof(buffer) - 8, fmt, args);
> +	va_end(args);
> +	if (n >= sizeof(buffer) - 8)
> +		die("protocol error: impossibly long line");
> +
> +	if (can_chunk) {
> +		unsigned len = n + 4, b = 4;
> +
> +		buffer[4] = '\r';
> +		buffer[5] = '\n';
> +		buffer[n + 6] = '\r';
> +		buffer[n + 7] = '\n';
> +
> +		while (n > 0) {
> +			buffer[--b] = hex(n);
> +			n >>= 4;
> +			len++;
> +		}
> +
> +		safe_write(1, buffer + b, len);
> +	} else
> +		safe_write(1, buffer + 6, n);
> +}

Maybe I am slightly confused, but I thought handling HTTP chunking for 
HTTP/1.1+ clients was usually done by Apache above the level of the CGI 
script?

	-hpa