Open
Conversation
|
@idealvin 这个 pr 没有回应哦 |
Ruiizgaby4
approved these changes
Sep 14, 2023
Owner
|
这块后续有空再清理 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
添加对http long-connection session模式的支持。即一直保持http连接,并且response不断追加发送数据的工作模式。
此模式常用于需要保持连接完成大量数据发送(如发送超长文件)或者数据不定时发送(如:视频实时推流,x-mixed-replace,部分web-socket应用场景等)。
主要改动(API接口部分):
1、在Http Response类(Res)中,新增一个send_body方法。此方法可在设置完header(add_header)后使用。用户每次调用send_body将即时发送一批body数据(因此,第一次调用send_body会附加Http response header的发送)。用户可以在保证当前协程函数(on_req)不退出的情况下任意多次调用send_body,直至业务数据发送完毕或者出错(send_body返回非0)。无论出错还是正常完成,退出当前协程函数即完成本http session资源的清理。
2、因为send_body(长连接)模式与set_body(短链接)模式互斥,因此修改set_body函数返回值为bool。用户调用set_body以后将无法调用send_body,同理用户调用send_body以后也将无法调用set_body(返回false)。
实现部分改动:
在Response-ctx类实现中,增加3个成员: