This is an automated email from the ASF dual-hosted git repository.

exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new edf9da088c NIFI-14978 Added HTTP Protocol Version to 
StandardWebClientServiceProvider (#10310)
edf9da088c is described below

commit edf9da088cc382a3fa1b03a9902c9d4463535dd6
Author: Pierre Villard <[email protected]>
AuthorDate: Tue Sep 16 15:41:59 2025 +0200

    NIFI-14978 Added HTTP Protocol Version to StandardWebClientServiceProvider 
(#10310)
    
    Signed-off-by: David Handermann <[email protected]>
---
 .../nifi/web/client/StandardWebClientService.java  | 22 ++++++++++++++++++++++
 .../service/StandardWebClientServiceProvider.java  | 20 +++++++++++++++++---
 2 files changed, 39 insertions(+), 3 deletions(-)

diff --git 
a/nifi-commons/nifi-web-client/src/main/java/org/apache/nifi/web/client/StandardWebClientService.java
 
b/nifi-commons/nifi-web-client/src/main/java/org/apache/nifi/web/client/StandardWebClientService.java
index 926af3f960..0ed83e3a46 100644
--- 
a/nifi-commons/nifi-web-client/src/main/java/org/apache/nifi/web/client/StandardWebClientService.java
+++ 
b/nifi-commons/nifi-web-client/src/main/java/org/apache/nifi/web/client/StandardWebClientService.java
@@ -43,6 +43,7 @@ import java.net.ProxySelector;
 import java.net.SocketAddress;
 import java.net.URI;
 import java.net.http.HttpClient;
+import java.net.http.HttpClient.Version;
 import java.net.http.HttpHeaders;
 import java.net.http.HttpRequest;
 import java.net.http.HttpResponse;
@@ -78,6 +79,8 @@ public class StandardWebClientService implements 
WebClientService, Closeable {
 
     private TlsContext tlsContext;
 
+    private Version httpVersion;
+
     /**
      * Standard Web Client Service constructor creates a Java HttpClient using 
default settings
      */
@@ -151,6 +154,17 @@ public class StandardWebClientService implements 
WebClientService, Closeable {
         this.httpClient = buildHttpClient();
     }
 
+    /**
+     * Set preferred HTTP protocol version for requests
+     *
+     * @param httpVersion HTTP protocol version
+     */
+    public void setHttpVersion(final Version httpVersion) {
+        Objects.requireNonNull(httpVersion, "HTTP Version required");
+        this.httpVersion = httpVersion;
+        this.httpClient = buildHttpClient();
+    }
+
     /**
      * Create HTTP Request builder starting with specified HTTP Request Method
      *
@@ -261,6 +275,10 @@ public class StandardWebClientService implements 
WebClientService, Closeable {
             }
         }
 
+        if (httpVersion != null) {
+            builder.version(httpVersion);
+        }
+
         return builder.build();
     }
 
@@ -378,6 +396,10 @@ public class StandardWebClientService implements 
WebClientService, Closeable {
                 requestBuilder.timeout(readTimeout);
             }
 
+            if (httpVersion != null) {
+                requestBuilder.version(httpVersion);
+            }
+
             final HttpRequest.BodyPublisher bodyPublisher = getBodyPublisher();
 
             return requestBuilder.method(httpRequestMethod.getMethod(), 
bodyPublisher)
diff --git 
a/nifi-extension-bundles/nifi-standard-services/nifi-web-client-provider-bundle/nifi-web-client-provider-service/src/main/java/org/apache/nifi/web/client/provider/service/StandardWebClientServiceProvider.java
 
b/nifi-extension-bundles/nifi-standard-services/nifi-web-client-provider-bundle/nifi-web-client-provider-service/src/main/java/org/apache/nifi/web/client/provider/service/StandardWebClientServiceProvider.java
index 50754761c0..ae039ea218 100644
--- 
a/nifi-extension-bundles/nifi-standard-services/nifi-web-client-provider-bundle/nifi-web-client-provider-service/src/main/java/org/apache/nifi/web/client/provider/service/StandardWebClientServiceProvider.java
+++ 
b/nifi-extension-bundles/nifi-standard-services/nifi-web-client-provider-bundle/nifi-web-client-provider-service/src/main/java/org/apache/nifi/web/client/provider/service/StandardWebClientServiceProvider.java
@@ -30,19 +30,21 @@ import org.apache.nifi.proxy.ProxyConfiguration;
 import org.apache.nifi.proxy.ProxyConfigurationService;
 import org.apache.nifi.ssl.SSLContextProvider;
 import org.apache.nifi.web.client.StandardHttpUriBuilder;
+import org.apache.nifi.web.client.StandardWebClientService;
 import org.apache.nifi.web.client.api.HttpUriBuilder;
+import org.apache.nifi.web.client.api.WebClientService;
+import org.apache.nifi.web.client.provider.api.WebClientServiceProvider;
 import org.apache.nifi.web.client.proxy.ProxyContext;
-import org.apache.nifi.web.client.StandardWebClientService;
 import org.apache.nifi.web.client.redirect.RedirectHandling;
 import org.apache.nifi.web.client.ssl.TlsContext;
-import org.apache.nifi.web.client.api.WebClientService;
-import org.apache.nifi.web.client.provider.api.WebClientServiceProvider;
 
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.X509ExtendedKeyManager;
 import javax.net.ssl.X509KeyManager;
 import javax.net.ssl.X509TrustManager;
+
 import java.net.Proxy;
+import java.net.http.HttpClient.Version;
 import java.time.Duration;
 import java.util.List;
 import java.util.Optional;
@@ -87,6 +89,14 @@ public class StandardWebClientServiceProvider extends 
AbstractControllerService
             .allowableValues(RedirectHandling.values())
             .build();
 
+    static final PropertyDescriptor HTTP_PROTOCOL_VERSION = new 
PropertyDescriptor.Builder()
+            .name("HTTP Protocol Version")
+            .description("Preferred HTTP protocol version for requests")
+            .required(true)
+            .defaultValue(Version.HTTP_2.name())
+            .allowableValues(Version.values())
+            .build();
+
     static final PropertyDescriptor SSL_CONTEXT_SERVICE = new 
PropertyDescriptor.Builder()
             .name("SSL Context Service")
             .description("SSL Context Service overrides system default TLS 
settings for HTTPS communication")
@@ -99,6 +109,7 @@ public class StandardWebClientServiceProvider extends 
AbstractControllerService
             READ_TIMEOUT,
             WRITE_TIMEOUT,
             REDIRECT_HANDLING_STRATEGY,
+            HTTP_PROTOCOL_VERSION,
             SSL_CONTEXT_SERVICE,
             PROXY_CONFIGURATION_SERVICE
     );
@@ -131,6 +142,9 @@ public class StandardWebClientServiceProvider extends 
AbstractControllerService
         final RedirectHandling redirectHandling = 
RedirectHandling.valueOf(redirectHandlingStrategy);
         standardWebClientService.setRedirectHandling(redirectHandling);
 
+        final Version httpVersion = 
context.getProperty(HTTP_PROTOCOL_VERSION).asAllowableValue(Version.class);
+        standardWebClientService.setHttpVersion(httpVersion);
+
         final PropertyValue sslContextServiceProperty = 
context.getProperty(SSL_CONTEXT_SERVICE);
         if (sslContextServiceProperty.isSet()) {
             final SSLContextProvider sslContextProvider = 
sslContextServiceProperty.asControllerService(SSLContextProvider.class);

Reply via email to