summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfengweihao <[email protected]>2021-09-13 17:12:18 +0800
committerfengweihao <[email protected]>2021-09-13 17:12:18 +0800
commit745187d0a3ef278348bb1dbe8d3ec2c69819c082 (patch)
tree143e83159578010fd81550e778fe9b127df0dafe
parent8d8b5eb039325bb5e1d94f32073b5211a8344f2b (diff)
bugfix: 修改brotli压缩等级v4.5.14-202109
-rw-r--r--plugin/protocol/http/src/http_convert.cpp2
-rw-r--r--plugin/protocol/http2/src/http2_common.cpp2
-rw-r--r--plugin/protocol/http2/src/http2_stream.cpp35
3 files changed, 20 insertions, 19 deletions
diff --git a/plugin/protocol/http/src/http_convert.cpp b/plugin/protocol/http/src/http_convert.cpp
index 89874ae..8cc57b6 100644
--- a/plugin/protocol/http/src/http_convert.cpp
+++ b/plugin/protocol/http/src/http_convert.cpp
@@ -249,6 +249,8 @@ struct hf_content_compress * hf_content_compress_create(unsigned int content_enc
{
cv_object->brenc_state = BrotliEncoderCreateInstance(NULL, NULL, NULL);
if (unlikely(cv_object->brenc_state == NULL)) goto __errout;
+
+ BrotliEncoderSetParameter(cv_object->brenc_state, BROTLI_PARAM_QUALITY, 3);
}
return cv_object;
diff --git a/plugin/protocol/http2/src/http2_common.cpp b/plugin/protocol/http2/src/http2_common.cpp
index de18eaf..89ae7f4 100644
--- a/plugin/protocol/http2/src/http2_common.cpp
+++ b/plugin/protocol/http2/src/http2_common.cpp
@@ -299,6 +299,8 @@ int deflate_init(struct z_stream_st **strm, int gzip)
(*strm)->brenc_state = BrotliEncoderCreateInstance(NULL, NULL, NULL);
if ( (*strm)->brenc_state == NULL)
ret = -1;
+
+ BrotliEncoderSetParameter((*strm)->brenc_state, BROTLI_PARAM_QUALITY, 3);
}
if (ret != Z_OK)
FREE(strm);
diff --git a/plugin/protocol/http2/src/http2_stream.cpp b/plugin/protocol/http2/src/http2_stream.cpp
index e36bd38..87da35f 100644
--- a/plugin/protocol/http2/src/http2_stream.cpp
+++ b/plugin/protocol/http2/src/http2_stream.cpp
@@ -836,20 +836,18 @@ nghttp2_submit_end_data_by_h2_half(struct tfe_h2_stream *h2_stream_info, int32_t
}
static enum tfe_stream_action
-nghttp2_submit_data_by_h2_half(struct tfe_h2_stream *connection,
- struct tfe_h2_session *h2_session,
- enum tfe_conn_dir dir)
+nghttp2_submit_data_by_h2_half(struct tfe_h2_stream *connection, struct tfe_h2_session *h2_session, enum tfe_conn_dir dir, int compress_result)
{
- enum tfe_stream_action stream_action = ACTION_DROP_DATA;
+ enum tfe_stream_action stream_action = ACTION_DROP_DATA;
struct tfe_h2_half_private *h2_half = tfe_h2_stream_get_half(h2_session, dir);
-
+
nghttp2_session *ngh2_session = tfe_h2_stream_get_nghttp2_session(connection, dir);
- if (h2_session->plugin_built_resp)
+ if (h2_session->plugin_built_resp && compress_result)
{
stream_action = nghttp2_frame_submit_built_resp(connection, h2_session);
}
- else if (h2_session->plugin_built_req)
+ else if (h2_session->plugin_built_req && compress_result)
{
stream_action = nghttp2_frame_submit_built_req(connection, h2_session);
}
@@ -1210,7 +1208,7 @@ nghttp2_submit_complete_data(struct tfe_h2_stream *h2_stream_info,
h2_half->body_state = H2_READ_STATE_COMPLETE;
h2_half->message_state = H2_READ_STATE_COMPLETE;
- stream_action = nghttp2_submit_data_by_h2_half(h2_stream_info, h2_session, dir);
+ stream_action = nghttp2_submit_data_by_h2_half(h2_stream_info, h2_session, dir, 1);
if (stream_action == ACTION_DROP_DATA)
{
xret = nghttp2_session_send(ngh2_session);
@@ -2041,7 +2039,7 @@ nghttp2_client_on_data_chunk_recv(nghttp2_session *session, uint8_t flags,
{
size_t len;
char *uncompr = NULL;
- int xret = -1;
+ int xret = -1, compress_result = 1;
enum tfe_stream_action stream_action = ACTION_DROP_DATA;
int uncompr_len = 0, __attribute__((__unused__))ret = 0;
const unsigned char *data;
@@ -2066,8 +2064,7 @@ nghttp2_client_on_data_chunk_recv(nghttp2_session *session, uint8_t flags,
evbuffer_add(resp->h2_payload.evbuf_body, input, input_len);
if (resp->h2_payload.gzip != HTTP2_CONTENT_ENCODING_NONE)
{
- ret = inflate_read(input, input_len, &uncompr, &uncompr_len,
- &resp->h2_payload.inflate, resp->h2_payload.gzip);
+ ret = inflate_read(input, input_len, &uncompr, &uncompr_len, &resp->h2_payload.inflate, resp->h2_payload.gzip);
if (((ret == Z_STREAM_END) || (ret == Z_OK)) && uncompr_len > 0)
{
input = (const uint8_t*)uncompr;
@@ -2075,6 +2072,7 @@ nghttp2_client_on_data_chunk_recv(nghttp2_session *session, uint8_t flags,
}
else
{
+ compress_result = 0;
/*if input is end_stream, send by nghttp2_submit_frame_data **/
if (flags != NGHTTP2_FLAG_END_STREAM && h2_session->plugin_built_resp == NULL)
{
@@ -2101,7 +2099,7 @@ nghttp2_client_on_data_chunk_recv(nghttp2_session *session, uint8_t flags,
data = input;
len = input_len;
- if (resp->body_state == H2_READ_STATE_BEGIN)
+ if (resp->body_state == H2_READ_STATE_BEGIN && compress_result)
{
if (resp->event_cb)
{
@@ -2117,12 +2115,11 @@ nghttp2_client_on_data_chunk_recv(nghttp2_session *session, uint8_t flags,
}
resp->body_state = H2_READ_STATE_READING;
}
- if (resp->body_state == H2_READ_STATE_READING)
+ if (resp->body_state == H2_READ_STATE_READING && compress_result)
{
- if (resp->event_cb)
+ if (resp->event_cb)
{
- resp->event_cb(resp, EV_HTTP_RESP_BODY_CONT, data, len,
- resp->event_cb_user);
+ resp->event_cb(resp, EV_HTTP_RESP_BODY_CONT, data, len, resp->event_cb_user);
}
if (flags & NGHTTP2_FLAG_END_STREAM)
{
@@ -2136,11 +2133,11 @@ nghttp2_client_on_data_chunk_recv(nghttp2_session *session, uint8_t flags,
{
FREE(&uncompr);
}
- stream_action = nghttp2_submit_data_by_h2_half(h2_stream_info, h2_session, CONN_DIR_UPSTREAM);
+ stream_action = nghttp2_submit_data_by_h2_half(h2_stream_info, h2_session, CONN_DIR_UPSTREAM, compress_result);
if (stream_action == ACTION_DROP_DATA)
{
xret = nghttp2_session_send(h2_stream_info->as_server);
- if (xret != 0)
+ if (xret != 0)
{
stream_action = ACTION_FORWARD_DATA;
TFE_LOG_ERROR(logger()->handle, "Fatal upstream(%d) send error: %s\n",stream_id, nghttp2_strerror(xret));
@@ -2476,7 +2473,7 @@ nghttp2_server_on_data_chunk_recv(nghttp2_session *session, uint8_t flags,
}
if (uncompr_len) FREE(&uncompr);
- stream_action = nghttp2_submit_data_by_h2_half(h2_stream_info, h2_session, CONN_DIR_DOWNSTREAM);
+ stream_action = nghttp2_submit_data_by_h2_half(h2_stream_info, h2_session, CONN_DIR_DOWNSTREAM, 1);
if (stream_action == ACTION_DROP_DATA){
xret = nghttp2_session_send(h2_stream_info->as_client);
if (xret != 0)