HTTP/1.1 protocol handlers fail to consistently set actual protocol version in the execution context
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpRequestExecutor.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpRequestExecutor.java
index baa499a..fea9cc2 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpRequestExecutor.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpRequestExecutor.java
@@ -127,13 +127,6 @@
         try {
             context.setAttribute(HttpCoreContext.SSL_SESSION, conn.getSSLSession());
             context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, conn.getEndpointDetails());
-            final ProtocolVersion transportVersion = request.getVersion();
-            if (transportVersion != null) {
-                if (transportVersion.greaterEquals(HttpVersion.HTTP_2)) {
-                    throw new UnsupportedHttpVersionException(transportVersion);
-                }
-                context.setProtocolVersion(transportVersion);
-            }
 
             conn.sendRequestHeader(request);
             if (streamListener != null) {
@@ -244,6 +237,11 @@
         Args.notNull(request, "HTTP request");
         Args.notNull(processor, "HTTP processor");
         Args.notNull(context, "HTTP context");
+        final ProtocolVersion transportVersion = request.getVersion();
+        if (transportVersion != null && transportVersion.greaterEquals(HttpVersion.HTTP_2)) {
+            throw new UnsupportedHttpVersionException(transportVersion);
+        }
+        context.setProtocolVersion(transportVersion != null ? transportVersion : HttpVersion.HTTP_1_1);
         context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
         processor.process(request, request.getEntity(), context);
     }
@@ -273,9 +271,7 @@
         Args.notNull(processor, "HTTP processor");
         Args.notNull(context, "HTTP context");
         final ProtocolVersion transportVersion = response.getVersion();
-        if (transportVersion != null) {
-            context.setProtocolVersion(transportVersion);
-        }
+        context.setProtocolVersion(transportVersion != null ? transportVersion : HttpVersion.HTTP_1_1);
         context.setAttribute(HttpCoreContext.HTTP_RESPONSE, response);
         processor.process(response, response.getEntity(), context);
     }
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpService.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpService.java
index 72ef10d..a34ca75 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpService.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpService.java
@@ -42,7 +42,9 @@
 import org.apache.hc.core5.http.HttpRequestMapper;
 import org.apache.hc.core5.http.HttpResponseFactory;
 import org.apache.hc.core5.http.HttpStatus;
+import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.http.UnsupportedHttpVersionException;
 import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.hc.core5.http.impl.Http1StreamListener;
 import org.apache.hc.core5.http.impl.ServerSupport;
@@ -179,9 +181,7 @@
             }
             conn.receiveRequestEntity(request);
             final ProtocolVersion transportVersion = request.getVersion();
-            if (transportVersion != null) {
-                context.setProtocolVersion(transportVersion);
-            }
+            context.setProtocolVersion(transportVersion != null ? transportVersion : HttpVersion.HTTP_1_1);
             context.setAttribute(HttpCoreContext.SSL_SESSION, conn.getSSLSession());
             context.setAttribute(HttpCoreContext.CONNECTION_ENDPOINT, conn.getEndpointDetails());
             context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
@@ -207,7 +207,12 @@
                 @Override
                 public void submitResponse(final ClassicHttpResponse response) throws HttpException, IOException {
                     try {
+                        final ProtocolVersion transportVersion = response.getVersion();
+                        if (transportVersion != null && transportVersion.greaterEquals(HttpVersion.HTTP_2)) {
+                            throw new UnsupportedHttpVersionException(transportVersion);
+                        }
                         ServerSupport.validateResponse(response, response.getEntity());
+                        context.setProtocolVersion(transportVersion != null ? transportVersion : HttpVersion.HTTP_1_1);
                         context.setAttribute(HttpCoreContext.HTTP_RESPONSE, response);
                         processor.process(response, response.getEntity(), context);
 
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
index aebd5aa..e508852 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
@@ -149,9 +149,7 @@
             if (transportVersion != null && transportVersion.greaterEquals(HttpVersion.HTTP_2)) {
                 throw new UnsupportedHttpVersionException(transportVersion);
             }
-            if (transportVersion != null) {
-                context.setProtocolVersion(transportVersion);
-            }
+            context.setProtocolVersion(transportVersion != null ? transportVersion : HttpVersion.HTTP_1_1);
             context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
 
             httpProcessor.process(request, entityDetails, context);
@@ -244,6 +242,7 @@
             }
         }
 
+        context.setProtocolVersion(transportVersion != null ? transportVersion : HttpVersion.HTTP_1_1);
         context.setAttribute(HttpCoreContext.HTTP_RESPONSE, response);
         httpProcessor.process(response, entityDetails, context);
 
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
index ab73f9b..65b4e4c 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
@@ -168,6 +168,7 @@
                 throw new HttpException("Invalid response: " + status);
             }
 
+            context.setProtocolVersion(transportVersion != null ? transportVersion : HttpVersion.HTTP_1_1);
             context.setAttribute(HttpCoreContext.HTTP_RESPONSE, response);
             httpProcessor.process(response, responseEntityDetails, context);
 
@@ -262,7 +263,7 @@
         if (transportVersion != null && transportVersion.greaterEquals(HttpVersion.HTTP_2)) {
             throw new UnsupportedHttpVersionException(transportVersion);
         }
-        context.setProtocolVersion(transportVersion);
+        context.setProtocolVersion(transportVersion != null ? transportVersion : HttpVersion.HTTP_1_1);
         context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
 
         try {