if (statcode == HTTP_STATUS_UNAUTHORIZED) { /* Authorization is required. */ uerr_t auth_err = RETROK; bool retry; /* Normally we are not interested in the response body. But if we are writing a WARC file we are: we like to keep everyting. */ if (warc_enabled) { int _err; type = resp_header_strdup (resp, "Content-Type"); _err = read_response_body (hs, sock, NULL, contlen, 0, chunked_transfer_encoding, u->url, warc_timestamp_str, warc_request_uuid, warc_ip, type, statcode, head); xfree (type);
if (_err != RETRFINISHED || hs->res < 0) { CLOSE_INVALIDATE (sock); retval = _err; goto cleanup; } else CLOSE_FINISH (sock); } else { /* Since WARC is disabled, we are not interested in the response body. */ if (keep_alive && !head_only && skip_short_body (sock, contlen, chunked_transfer_encoding))//调用函数 CLOSE_FINISH (sock); else CLOSE_INVALIDATE (sock); } .............
staticbool skip_short_body (int fd, wgint contlen, bool chunked) { enum { SKIP_SIZE = 512, /* size of the download buffer */ SKIP_THRESHOLD = 4096/* the largest size we read */ }; wgint remaining_chunk_size = 0; char dlbuf[SKIP_SIZE + 1]; dlbuf[SKIP_SIZE] = '\0'; /* so DEBUGP can safely print it */
/* If the body is too large, it makes more sense to simply close the connection than to try to read the body. */ if (contlen > SKIP_THRESHOLD) returnfalse;
while (contlen > 0 || chunked) { int ret; if (chunked) { if (remaining_chunk_size == 0) { char *line = fd_read_line (fd); char *endl; if (line == NULL) break;
if (remaining_chunk_size == 0)//只判断是不是0,没有判断不能是负数 { line = fd_read_line (fd); xfree (line); break; } }
contlen = MIN (remaining_chunk_size, SKIP_SIZE);//出问题 }
DEBUGP (("Skipping %s bytes of body: [", number_to_static_string (contlen)));
ret = fd_read (fd, dlbuf, MIN (contlen, SKIP_SIZE), -1); if (ret <= 0) { /* Don't normally report the error since this is an optimization that should be invisible to the user. */ DEBUGP (("] aborting (%s).\n", ret < 0 ? fd_errstr (fd) : "EOF received")); returnfalse; } contlen -= ret;
if (chunked) { remaining_chunk_size -= ret; if (remaining_chunk_size == 0) { char *line = fd_read_line (fd); if (line == NULL) returnfalse; else xfree (line); } }
/* Safe even if %.*s bogusly expects terminating \0 because we've zero-terminated dlbuf above. */ DEBUGP (("%.*s", ret, dlbuf)); }