Lines Matching refs:toybuf
288 sprintf(toybuf, "GET /%s HTTP/1.1\r\nHost: %s\r\n"
291 if (FLAG(d)) printf("--- Request\n%s", toybuf);
294 wget_write(toybuf, strlen(toybuf));
296 // Greedily read the HTTP response until either complete or toybuf is full
297 index = toybuf;
298 while ((len = wget_read(index, sizeof(toybuf) - (index - toybuf))) > 0)
302 // Valid ranges toybuf[0...index) valid length is (index - toybuf)
303 // Header ranges toybuf[0...body) header length strlen(toybuf)
304 // Remnant Body toybuf[body...index) valid remnant body length is len
309 body = memmem(toybuf, index - toybuf, "\r\n\r\n", 4);
314 if (FLAG(d)) printf("--- Response\n%s\n\n", toybuf);
316 status = strtol(strafter(toybuf, " "), NULL, 10);
319 TT.url = wget_redirect(toybuf);
325 TT.filename = wget_filename(toybuf, path);
331 chunked = wget_has_header(toybuf, WGET_CHUNKED);
339 memmove(toybuf, body - 2, len);
341 memmove(toybuf, body, len);
344 // len is the size remaining in toybuf
350 xwrite(fd, toybuf, len);
354 xwrite(fd, toybuf, c_len);
356 memmove(toybuf, toybuf + c_len, len);
362 // through and go read more into toybuf.
365 if (strncmp(toybuf, "\r\n", 2) != 0) error_exit("chunk boundary");
368 // read more into toybuf.
369 c = memmem(toybuf + 2, len - 2, "\r\n",2);
371 c_len = strtol(toybuf + 2, NULL, 16);
373 len = len - (c - toybuf) - 2;
374 memmove(toybuf, c + 2, len);
378 if (len == sizeof(toybuf)) error_exit("chunk overflow");
380 xwrite(fd, toybuf, len);
383 } while ((len += wget_read(toybuf + len, sizeof(toybuf) - len)) > 0);