- return 0;
- }
- else
- { /* not chunked ; inside body */
- /* i += 2 seems not to work with GCC -O2 ..
- so i+2 is used instead .. */
- if (len >= (i+2)+ content_len)
- return (i+2)+ content_len;
+ return 0;
+}
+
+static int cs_complete_http(const char *buf, int len, int head_only)
+{
+ /* deal with HTTP request/response */
+ int i = 2, content_len = 0, chunked = 0;
+
+ if (len < 6)
+ return 0;
+
+ /* if dealing with HTTP responses - then default
+ content length is unlimited (socket close) */
+ if (!head_only && !memcmp(buf, "HTTP/", 5))
+ content_len = -1;
+
+#if 0
+ printf("len = %d\n", len);
+ fwrite (buf, 1, len, stdout);
+ printf("----------\n");
+#endif
+ while (i <= len-2)
+ {
+ if (i > 8192)
+ {
+ return i; /* do not allow more than 8K HTTP header */
+ }
+ if (skip_crlf(buf, len, &i))
+ {
+ if (skip_crlf(buf, len, &i))
+ {
+ /* inside content */
+ if (chunked)
+ return cs_read_chunk(buf, i, len);
+ else
+ { /* not chunked ; inside body */
+ if (content_len == -1)
+ return 0; /* no content length */
+ else if (len >= i + content_len)
+ {
+ return i + content_len;