@@ -61,16 +61,28 @@ public ResponseEntity<String> sendRequest(JavaHttpRequest requestData, HttpHeade
6161 // DNS-Auflösung vor dem Request (diagnostisch)
6262 String resolvedIps = resolveDns (currentUri .getHost ());
6363
64- // Erster Request mit HTTP/2, Fallback auf HTTP/1.1 bei Protocol-Fehler
64+ // Erster Request mit HTTP/2, Fallback auf HTTP/1.1 bei Verbindungs- oder Protokollfehler
6565 record RequestResult (HttpClient activeClient , HttpResponse <String > response , boolean usedFallback ) {}
6666 RequestResult initial ;
6767 try {
68- initial = new RequestResult (client ,
69- client .send (buildRequest (currentUri , currentMethod , currentBody , requestData , incomingHeaders ),
70- BodyHandlers .ofString ()),
71- false );
68+ HttpResponse <String > h2response = client .send (
69+ buildRequest (currentUri , currentMethod , currentBody , requestData , incomingHeaders ),
70+ BodyHandlers .ofString ());
71+ // 502 mit Envoy-Protokollfehler → HTTP/2 wird vom Upstream nicht unterstützt
72+ boolean isProtocolError = h2response .statusCode () == 502
73+ && h2response .body () != null
74+ && h2response .body ().contains ("protocol error" );
75+ if (isProtocolError ) {
76+ logger .warn ("HTTP/2 502 protocol error, Fallback auf HTTP/1.1" );
77+ initial = new RequestResult (clientHttp11 ,
78+ clientHttp11 .send (buildRequest (currentUri , currentMethod , currentBody , requestData , incomingHeaders ),
79+ BodyHandlers .ofString ()),
80+ true );
81+ } else {
82+ initial = new RequestResult (client , h2response , false );
83+ }
7284 } catch (IOException e ) {
73- logger .warn ("HTTP/2 fehlgeschlagen ({}), Fallback auf HTTP/1.1" , e .getMessage ());
85+ logger .warn ("HTTP/2 Verbindungsfehler ({}), Fallback auf HTTP/1.1" , e .getMessage ());
7486 initial = new RequestResult (clientHttp11 ,
7587 clientHttp11 .send (buildRequest (currentUri , currentMethod , currentBody , requestData , incomingHeaders ),
7688 BodyHandlers .ofString ()),
0 commit comments