diff --git a/src/comstack.c b/src/comstack.c index ea5b3eef6..6f1f847ef 100644 --- a/src/comstack.c +++ b/src/comstack.c @@ -381,6 +381,8 @@ static int cs_complete_http(const char *buf, int len, int head_only) head_only = 1; else if (!memcmp(buf + j, "304", 3)) head_only = 1; + else + content_len = -1; break; } } @@ -406,7 +408,9 @@ static int cs_complete_http(const char *buf, int len, int head_only) return cs_read_chunk(buf, i, len); else { /* not chunked ; inside body */ - if (len >= i + content_len) + if (content_len == -1) + return 0; /* no content length */ + else if (len >= i + content_len) { return i + content_len; } diff --git a/test/test_comstack.c b/test/test_comstack.c index 3638d50b7..381ecb88f 100644 --- a/test/test_comstack.c +++ b/test/test_comstack.c @@ -170,7 +170,7 @@ static void tst_http_response(void) YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0); YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0); - YAZ_CHECK_EQ(cs_complete_auto(http_buf, 24), 19); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 24), 0); } { /* no content, no headers */