Skip to content

支持 http 处理链返回 HTTP_STATUS_WANT_CLOSE #716

New issue

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

House-Men
Copy link
Contributor

能够在各个处理链线程安全的通过返回此值要求无视Http头keep-alive强制关闭连接,甚至可选搭配处理链的回调中将ctx->writer->state = hv::HttpResponseWriter::SEND_END; 实现取消hv内部默认响应http状态包变为自定义响应非http报文或不响应任何数据,让非法访问无法探测外网端口的具体服务性质。

@ithewei
Copy link
Owner

ithewei commented Apr 18, 2025

这个感觉没太大必要,理解成本也高,想关闭连接可直接调用ctx->writer->close(),不想响应非http报文,也可以直接通过ctx->writer->write()发送任意的数据

@House-Men
Copy link
Contributor Author

House-Men commented Apr 18, 2025

这个感觉没太大必要,理解成本也高,想关闭连接可直接调用ctx->writer->close(),不想响应非http报文,也可以直接通过ctx->writer->write()发送任意的数据

你说的这个方式起初我就尝试过了存在缺陷后才支持的返回WANT_CLOSE方案
因为 ctx->writer->close 必须使用异步关闭,如果同步关闭会导致处理链后面的执行逻辑引用野指针崩溃,而异步虽然能关闭但存在延迟需要等待下一次loop事件关闭,另外你说的通过writer->write发送任意数据是可以但无法阻止默认处理链的发送HTTP响应头信息,而SendHttpStatusResponse函数 if (HandleHttpRequest() == HTTP_STATUS_NEXT) return 0; 这一行修改就为了修复 ctx->writer->state = hv::HttpResponseWriter::SEND_END; 阻止响应HTTP头无效的问题,因为SendHttpStatusResponse中调用 HandleHttpRequest() 与 onMessageComplete函数中调用 HandleHttpRequest() 因缺少 if (status_code != HTTP_STATUS_NEXT) SendHttpResponse(); 造成行为不一致导致有些情况能阻止响应有些情况不行,还有if (error == 0 && keepalive) { 这行修改是阻止已经error错误任然因keepalive触发Reset复位问题。

@House-Men
Copy link
Contributor Author

@ithewei Channel默认的close 就是async=false 同步方式 在Http处理链回调使用会崩溃反而会增加理解使用成本

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants