@@ -64,13 +64,24 @@ class VertxHttpClient implements HttpClient {
6464 private static final Duration EXPECT_CONTINUE_TIMEOUT = Duration .ofSeconds (1 );
6565
6666 private static final ReflectiveInvoker REQUEST_RESET ;
67+ private static final ReflectiveInvoker REQUEST_WRITE_HEAD ;
6768 static {
6869 // In order to support both Vert.x 4.5 and 5.x reflection is needed to reset an HttpClientRequest.
6970 // HttpClientRequest.reset(long, Throwable) is available in both versions, but it returns boolean in 4.5 and
7071 // Future<Void> in 5.x, so a call compiled against one version fails with NoSuchMethodError on the other.
7172 try {
7273 Method method = HttpClientRequest .class .getMethod ("reset" , long .class , Throwable .class );
7374 REQUEST_RESET = ReflectionUtils .getMethodInvoker (HttpClientRequest .class , method , false );
75+
76+ // Vert.x 5.1 introduced writeHead() and deprecated sendHead() for removal. Resolve the appropriate method
77+ // at runtime so the transport can still be compiled and used with Vert.x 4.5 and 5.0.
78+ Method writeHeadMethod ;
79+ try {
80+ writeHeadMethod = HttpClientRequest .class .getMethod ("writeHead" );
81+ } catch (NoSuchMethodException ex ) {
82+ writeHeadMethod = HttpClientRequest .class .getMethod ("sendHead" );
83+ }
84+ REQUEST_WRITE_HEAD = ReflectionUtils .getMethodInvoker (HttpClientRequest .class , writeHeadMethod , false );
7485 } catch (Exception ex ) {
7586 // Fail here as the method isn't available and this HttpClient wouldn't be usable anyway.
7687 throw LOGGER .logExceptionAsError (new IllegalStateException (ex ));
@@ -288,7 +299,7 @@ private void sendBody(ContextView contextView, HttpRequest azureRequest, Progres
288299 writeOnce .run ();
289300 });
290301 long headerWrite = writeWatcher .start ();
291- vertxRequest . sendHead ( ).onSuccess (ignored -> writeWatcher .pause (headerWrite )).onFailure (promise ::tryFail );
302+ writeHead ( vertxRequest ).onSuccess (ignored -> writeWatcher .pause (headerWrite )).onFailure (promise ::tryFail );
292303 } else {
293304 writeBody (contextView , azureRequest , progressReporter , vertxRequest , promise , body , writeWatcher );
294305 }
@@ -339,6 +350,15 @@ private void writeBody(ContextView contextView, HttpRequest azureRequest, Progre
339350 }
340351 }
341352
353+ @ SuppressWarnings ("unchecked" )
354+ private static Future <Void > writeHead (HttpClientRequest vertxRequest ) {
355+ try {
356+ return (Future <Void >) REQUEST_WRITE_HEAD .invokeWithArguments (vertxRequest );
357+ } catch (Exception ex ) {
358+ return Future .failedFuture (ex );
359+ }
360+ }
361+
342362 private static void resetRequest (HttpClientRequest vertxRequest , long code , Throwable cause ) {
343363 try {
344364 REQUEST_RESET .invokeWithArguments (vertxRequest , code , cause );
0 commit comments