-
Notifications
You must be signed in to change notification settings - Fork 376
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
feat: add compress api for coro client #597
feat: add compress api for coro client #597
Conversation
helintongh
commented
Jun 10, 2024
•
edited
Loading
edited
- add multiple encoding type support
- add encoding for coro client
- coro server add accept-encoding check
Code Coverage Report
|
include/cinatra/coro_http_client.hpp
Outdated
if (parser_.get_header_value("Content-Encoding") == "gzip") | ||
encoding_type_ = content_encoding::gzip; | ||
else if (parser_.get_header_value("Content-Encoding") == "deflate") | ||
encoding_type_ = content_encoding::deflate; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里有点问题,"Content-Encoding"可能有多个字段,有可能一个字段有多个encoding方式,比如:
"Content-Encoding":"gzip"
"Content-Encoding":"deflate"
或者
"Content-Encoding": "gzip, deflate, br"
另外reply的时候如果发现set_status_and_content时已经设置了gzip或者deflate,就按设置的方式去reply,如果没有设置,但是头里面又能找到gzip或者deflate,那么就默认选择gzip;如果只有一种encoding就按头里面的来。
如果头里面没有Content-Encoding
,但是用户设置response的时候又指定了gzip或deflate,则忽略它,不去压缩。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
设置response的时候是解析客户端的Accept-Encoding,如果包含当前用户设置的按照用户设置的reponse进行响应。
如果不包含或无此字段则按照原始的响应
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
1. add multiple encoding type support 2. add encoding for coro client 3. coro server add accept-encoding check
c46cbf5
to
f101377
Compare
Code Coverage Report
|
Code Coverage Report
|
@@ -145,6 +145,25 @@ class coro_http_request { | |||
|
|||
bool is_req_ranges() { return parser_.is_req_ranges(); } | |||
|
|||
std::string get_accept_encoding() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
返回类型改成std::string_view
@@ -52,26 +52,63 @@ class coro_http_response { | |||
} | |||
void set_status_and_content( | |||
status_type status, std::string content = "", | |||
content_encoding encoding = content_encoding::none) { | |||
set_status_and_content_view(status, std::move(content), encoding, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::string client_encoding_type的类型改成std::string_view
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已经修改
Code Coverage Report
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM