Skip to content

Commit

Permalink
Merge pull request #464 from lostsnow/fix/replay-request-header-and-body
Browse files Browse the repository at this point in the history
fixes replay request header and body
  • Loading branch information
lostsnow authored Feb 13, 2023
2 parents 5cab967 + 6503d70 commit 9b28d8a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.apache.http.client.entity.GzipCompressingEntity;
import org.apache.http.client.methods.*;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.*;
import org.apache.http.util.EntityUtils;
Expand Down Expand Up @@ -34,7 +35,7 @@ protected static StringBuilder sendRequest(HttpMethods method, String url, Strin

HttpEntity reqBody = null;
try {
if (HttpMethods.POST.equals(method) && data != null) {
if (HttpMethods.POST.equals(method) && data != null && !data.isEmpty()) {
reqBody = new GzipCompressingEntity(new StringEntity(data, "UTF-8"));
}
} catch (Throwable e) {
Expand All @@ -60,11 +61,19 @@ public static StringBuilder sendReplayRequest(String method, String url, String

HttpEntity reqBody = null;
try {
if (HttpMethods.POST.equals(method) && data != null) {
reqBody = new StringEntity(data, "UTF-8");
if (HttpMethods.POST.equals(method) && data != null && !data.isEmpty()) {
String contentType = headers.get("content-type");
if (contentType == null || contentType.isEmpty()) {
reqBody = new StringEntity(data, "UTF-8");
} else if (!contentType.contains(";")) {
reqBody = new StringEntity(data, ContentType.create(contentType, "UTF-8"));
} else {
reqBody = new StringEntity(data, ContentType.parse(contentType));
}
}
} catch (Throwable e) {
DongTaiLog.error(ErrorCode.HTTP_CLIENT_PREPARE_REQUEST_BODY_FAILED, url, e);
DongTaiLog.warn(ErrorCode.HTTP_CLIENT_PREPARE_REQUEST_BODY_FAILED, url, e);
return response;
}
response = sendRequest(client, m, url, reqBody, headers, null);
DongTaiLog.trace("dongtai replay request url is {}, request is {}, response is {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ private static void doReplay(IastReplayModel replayModel) {
headers.put("dongtai-replay-id", String.valueOf(replayModel.getReplayId()));
headers.put("dongtai-relation-id", String.valueOf(replayModel.getRelationId()));
headers.put("dongtai-replay-type", String.valueOf(replayModel.getReplayType()));
headers.remove("content-length");
headers.remove("transfer-encoding");

String url = replayModel.getFullUrl();
if (url != null) {
Expand Down

0 comments on commit 9b28d8a

Please sign in to comment.