We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
当前 header 和 body 用的是一个 struct buffer wb, 发送响应时要先发header,再发body.
struct buffer wb
一个 handler 在刚开始可能并不能确定是要返回 200, 还是 500, 在执行过程中会有输出, 这时只能用一个临时 buffer 来缓存这些输出, 当能确定返回状态码后, 先 send headers, 再把这个临时 buffer 的内容 append 到 wb 里,导致内存用量 x2.
比如:
// 一些逻辑产生输出 struct buffer tmp; buffer_put_data(&tmp, "xxx", 3); // 执行到这里发现出错了 if (error) { buffer_free(&tmp); conn->send_error(...) } else { conn->send_head(conn, HTTP_STATUS_OK, ...) conn->end_headers(conn); conn->send(conn, buffer_data(&tmp), buffer_length(&tmp)); buffer_free(&tmp); }
header 和 body 使用两个 buffer 的话, 可以把 body buffer 通过接口让 handler 可以把数据缓存进去, conn->send() 时先发 header buffer, 再发 body buffer.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
当前 header 和 body 用的是一个
struct buffer wb
, 发送响应时要先发header,再发body.一个 handler 在刚开始可能并不能确定是要返回 200, 还是 500, 在执行过程中会有输出, 这时只能用一个临时 buffer 来缓存这些输出, 当能确定返回状态码后, 先 send headers, 再把这个临时 buffer 的内容 append 到 wb 里,导致内存用量 x2.
比如:
header 和 body 使用两个 buffer 的话, 可以把 body buffer 通过接口让 handler 可以把数据缓存进去, conn->send() 时先发 header buffer, 再发 body buffer.
The text was updated successfully, but these errors were encountered: