Skip to content

Commit

Permalink
0004442: Invalid lines in batch with HTTP2
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Jun 23, 2020
1 parent 6dc8b69 commit 8856d5d
Showing 1 changed file with 15 additions and 10 deletions.
Expand Up @@ -143,11 +143,14 @@ protected synchronized Response getResponse() throws IOException {
OkHttpClient client = clientBuilder.build();

if (log.isDebugEnabled()) {
logHeaders(request);
logHeaders("Request", request.headers());
}

try {
response = client.newCall(request).execute();
if (log.isDebugEnabled()) {
logHeaders("Response", response.headers());
}
} catch (IOException e) {
exception = e;
throw e;
Expand All @@ -159,13 +162,14 @@ protected synchronized Response getResponse() throws IOException {
return response;
}

protected void logHeaders(Request request) {
Headers headers = request.headers();
protected void logHeaders(String name, Headers headers) {
StringBuilder sb = new StringBuilder("{");
Iterator<Pair<String, String>> iter = headers.iterator();
while (iter.hasNext()) {
Pair<String, String> header = iter.next();
if (!header.getFirst().equalsIgnoreCase(WebConstants.HEADER_SESSION_ID) &&
!header.getFirst().equalsIgnoreCase(WebConstants.HEADER_SET_SESSION_ID) &&
!header.getFirst().equalsIgnoreCase(WebConstants.REG_PASSWORD) &&
!header.getFirst().equalsIgnoreCase(WebConstants.HEADER_SECURITY_TOKEN)) {
if (sb.length() > 1) {
sb.append(", ");
Expand All @@ -174,7 +178,7 @@ protected void logHeaders(Request request) {
}
}
sb.append("}");
log.debug("Request headers: {}", sb.toString());
log.debug(name + " headers: {}", sb.toString());
}

@Override
Expand Down Expand Up @@ -211,7 +215,7 @@ protected void waitForResponse() throws IOException {
}
}
if (exception != null) {
throw exception;
throw new IOException(exception);
}
}
}
Expand Down Expand Up @@ -321,9 +325,6 @@ public void addRequestProperty(String key, String value) {

protected void detectMediaType(String key, String value) {
if (key.equalsIgnoreCase("Content-Type")) {
if (value.equals("gzip")) {
value = "application/gzip";
}
mediaType = MediaType.parse(value);
}
}
Expand Down Expand Up @@ -389,9 +390,13 @@ protected BlockingRequestBody(Http2Connection connection) {
public MediaType contentType() {
if (mediaType != null) {
return mediaType;
} else if (requestMethod.equalsIgnoreCase("PUT")) {
return null;
} else if (requestMethod.equalsIgnoreCase("POST")) {
return MediaType.parse("application/x-www-form-urlencoded");
} else {
return MediaType.parse("text/plain");
}
return requestMethod.equalsIgnoreCase("POST") ? MediaType.parse("application/x-www-form-urlencoded"):
MediaType.parse("text/plain");
}

@Override
Expand Down

0 comments on commit 8856d5d

Please sign in to comment.