Skip to content

Commit

Permalink
gzip对request增加null判断
Browse files Browse the repository at this point in the history
  • Loading branch information
tywo45 committed Jul 13, 2019
1 parent 31479e5 commit dfe6b6e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,11 @@
* 2017年8月4日 上午9:41:12
*/
public class HttpResponseEncoder {

@SuppressWarnings("unused")
private static Logger log = LoggerFactory.getLogger(HttpResponseEncoder.class);

public static final int MAX_HEADER_LENGTH = 20480;

public static final int HEADER_SERVER_LENGTH = HeaderName.Server.bytes.length + HeaderValue.Server.TIO.bytes.length + 3;

public static final int HEADER_DATE_LENGTH_1 = HeaderName.Date.bytes.length + 3;

public static final int HEADER_FIXED_LENGTH = HEADER_SERVER_LENGTH + HEADER_DATE_LENGTH_1;
private static Logger log = LoggerFactory.getLogger(HttpResponseEncoder.class);
public static final int MAX_HEADER_LENGTH = 20480;
public static final int HEADER_SERVER_LENGTH = HeaderName.Server.bytes.length + HeaderValue.Server.TIO.bytes.length + 3;
public static final int HEADER_DATE_LENGTH_1 = HeaderName.Date.bytes.length + 3;
public static final int HEADER_FIXED_LENGTH = HEADER_SERVER_LENGTH + HEADER_DATE_LENGTH_1;

/**
*
Expand Down Expand Up @@ -66,16 +60,14 @@ public static ByteBuffer encode(HttpResponse httpResponse, GroupContext groupCon
}
}



if (body != null) {
//处理gzip
try {
HttpGzipUtils.gzip(httpRequest, httpResponse);
} catch (Exception e) {
log.error(e.toString(), e);
}

body = httpResponse.body;
bodyLength = body.length;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,22 @@ public static void gzip(HttpRequest request, HttpResponse response) {
if (response == null) {
return;
}
//
// // 已经gzip过了,就不必再压缩了
// if (response.isHasGzipped()) {
// return;
// }

if (request.getIsSupportGzip()) {
//
// // 已经gzip过了,就不必再压缩了
// if (response.isHasGzipped()) {
// return;
// }

if (request != null && request.getIsSupportGzip()) {
gzip(response);
} else {
log.warn("{}, 不支持gzip, {}", request.getClientIp(), request.getHeader(HttpConst.RequestHeaderKey.User_Agent));
if (request != null) {
log.warn("{}, 不支持gzip, {}", request.getClientIp(), request.getHeader(HttpConst.RequestHeaderKey.User_Agent));
} else {
log.info("request对象为空");
}

}
}

Expand Down

0 comments on commit dfe6b6e

Please sign in to comment.