This is an automated email from the ASF dual-hosted git repository. snagel pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nutch.git
The following commit(s) were added to refs/heads/master by this push: new 21018be NUTCH-2760 protocol-okhttp: properly record HTTP version in request message header - use HTTP protocol from connection (instead of response) for request message stored in metadata (if property `store.http.request` is true) new 3bbc6dd Merge pull request #489 from sebastian-nagel/NUTCH-2760-protocol-okhttp-request-message-http-version 21018be is described below commit 21018bea76e14976802f49b7856f1b444331bd70 Author: Sebastian Nagel <sna...@apache.org> AuthorDate: Fri Dec 13 12:46:02 2019 +0100 NUTCH-2760 protocol-okhttp: properly record HTTP version in request message header - use HTTP protocol from connection (instead of response) for request message stored in metadata (if property `store.http.request` is true) --- .../org/apache/nutch/protocol/okhttp/OkHttp.java | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/plugin/protocol-okhttp/src/java/org/apache/nutch/protocol/okhttp/OkHttp.java b/src/plugin/protocol-okhttp/src/java/org/apache/nutch/protocol/okhttp/OkHttp.java index 22183c0..b4edb19 100644 --- a/src/plugin/protocol-okhttp/src/java/org/apache/nutch/protocol/okhttp/OkHttp.java +++ b/src/plugin/protocol-okhttp/src/java/org/apache/nutch/protocol/okhttp/OkHttp.java @@ -54,6 +54,7 @@ import okhttp3.Connection; import okhttp3.Headers; import okhttp3.Interceptor; import okhttp3.OkHttpClient; +import okhttp3.Protocol; import okhttp3.Request; public class OkHttp extends HttpBase { @@ -220,6 +221,15 @@ public class OkHttp extends HttpBase { class HTTPHeadersInterceptor implements Interceptor { + private String getNormalizedProtocolName(Protocol protocol) { + String name = protocol.toString().toUpperCase(Locale.ROOT); + if ("H2".equals(name)) { + // back-ward compatible protocol version name + name = "HTTP/2"; + } + return name; + } + @Override public okhttp3.Response intercept(Interceptor.Chain chain) throws IOException { @@ -233,12 +243,6 @@ public class OkHttp extends HttpBase { Request request = chain.request(); okhttp3.Response response = chain.proceed(request); - String httpProtocol = response.protocol().toString() - .toUpperCase(Locale.ROOT); - if (useHttp2 && "H2".equals(httpProtocol)) { - // back-ward compatible protocol name - httpProtocol = "HTTP/2"; - } StringBuilder requestverbatim = null; StringBuilder responseverbatim = null; @@ -252,7 +256,9 @@ public class OkHttp extends HttpBase { if (query != null) { requestverbatim.append('?').append(query); } - requestverbatim.append(' ').append(httpProtocol).append("\r\n"); + requestverbatim.append(' ') + .append(getNormalizedProtocolName(connection.protocol())) + .append("\r\n"); Headers headers = request.headers(); @@ -269,8 +275,8 @@ public class OkHttp extends HttpBase { if (storeHttpHeaders) { responseverbatim = new StringBuilder(); - responseverbatim.append(httpProtocol).append(' ') - .append(response.code()); + responseverbatim.append(getNormalizedProtocolName(response.protocol())) + .append(' ').append(response.code()); if (!response.message().isEmpty()) { responseverbatim.append(' ').append(response.message()); }