Tinyhttpd icon indicating copy to clipboard operation
Tinyhttpd copied to clipboard

一定要discard headers么?

Open vmjie opened this issue 7 years ago • 4 comments

sprintf(path, "htdocs%s", url);
if (path[strlen(path) - 1] == '/')
    strcat(path, "index.html");
if (stat(path, &st) == -1) {
    while ((numchars > 0) && strcmp("\n", buf))  /* read & discard headers */
        numchars = get_line(client, buf, sizeof(buf));
    not_found(client);
}

这里discard headers是一定需要的么?

vmjie avatar Mar 29 '17 15:03 vmjie

在 HTTP 请求报文中,请求行,请求头部,空行都是必有的,如果不读取,会留在缓存区吧。

liuyunbin avatar Sep 14 '17 06:09 liuyunbin

@liuyunbin 后面就是close了,close不会丢掉缓存区吗?

lanthree avatar Oct 23 '17 09:10 lanthree

mark

linzewei1991 avatar Jan 19 '19 12:01 linzewei1991

@liuyunbin 后面就是close了,close不会丢掉缓存区吗?

我觉得是不是因为考虑到,后续会有其他请求,这里将缓冲区读完,避免缓冲区内容堆积呢?纯属猜测😂

hellowack avatar May 06 '22 13:05 hellowack