46
46
import java .util .Iterator ;
47
47
import java .util .LinkedHashMap ;
48
48
import java .util .List ;
49
- import java .util .ListIterator ;
50
49
import java .util .Locale ;
51
50
import java .util .Map ;
52
51
import java .util .NoSuchElementException ;
@@ -468,6 +467,11 @@ private void setupConnection(URL url) throws IOException {
468
467
uc .setRequestProperty (e .getKey (), v );
469
468
}
470
469
470
+ setRequestMethod (uc );
471
+ uc .setRequestProperty ("Accept-Encoding" , "gzip" );
472
+ }
473
+
474
+ private void setRequestMethod (HttpURLConnection uc ) throws IOException {
471
475
try {
472
476
uc .setRequestMethod (method );
473
477
} catch (ProtocolException e ) {
@@ -479,8 +483,23 @@ private void setupConnection(URL url) throws IOException {
479
483
} catch (Exception x ) {
480
484
throw (IOException )new IOException ("Failed to set the custom verb" ).initCause (x );
481
485
}
486
+ // sun.net.www.protocol.https.DelegatingHttpsURLConnection delegates to another HttpURLConnection
487
+ try {
488
+ Field $delegate = uc .getClass ().getDeclaredField ("delegate" );
489
+ $delegate .setAccessible (true );
490
+ Object delegate = $delegate .get (uc );
491
+ if (delegate instanceof HttpURLConnection ) {
492
+ HttpURLConnection nested = (HttpURLConnection ) delegate ;
493
+ setRequestMethod (nested );
494
+ }
495
+ } catch (NoSuchFieldException x ) {
496
+ // no problem
497
+ } catch (IllegalAccessException x ) {
498
+ throw (IOException )new IOException ("Failed to set the custom verb" ).initCause (x );
499
+ }
482
500
}
483
- uc .setRequestProperty ("Accept-Encoding" , "gzip" );
501
+ if (!uc .getRequestMethod ().equals (method ))
502
+ throw new IllegalStateException ("Failed to set the request method to " +method );
484
503
}
485
504
486
505
private <T > T parse (Class <T > type , T instance ) throws IOException {
0 commit comments