Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3d1bed0

Browse filesBrowse files
committed
In JDK I'm using (Java8), I get a delegating HttpURLConnection that breaks the hack to set the method.
This change makes this hack even worse, but this is the only way I can think of, since I cannot update HttpURLConnection.methods that is static final.
1 parent 5c9ea9b commit 3d1bed0
Copy full SHA for 3d1bed0

File tree

Expand file treeCollapse file tree

1 file changed

+21
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+21
-2
lines changed

‎src/main/java/org/kohsuke/github/Requester.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/Requester.java
+21-2Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import java.util.Iterator;
4747
import java.util.LinkedHashMap;
4848
import java.util.List;
49-
import java.util.ListIterator;
5049
import java.util.Locale;
5150
import java.util.Map;
5251
import java.util.NoSuchElementException;
@@ -468,6 +467,11 @@ private void setupConnection(URL url) throws IOException {
468467
uc.setRequestProperty(e.getKey(), v);
469468
}
470469

470+
setRequestMethod(uc);
471+
uc.setRequestProperty("Accept-Encoding", "gzip");
472+
}
473+
474+
private void setRequestMethod(HttpURLConnection uc) throws IOException {
471475
try {
472476
uc.setRequestMethod(method);
473477
} catch (ProtocolException e) {
@@ -479,8 +483,23 @@ private void setupConnection(URL url) throws IOException {
479483
} catch (Exception x) {
480484
throw (IOException)new IOException("Failed to set the custom verb").initCause(x);
481485
}
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+
}
482500
}
483-
uc.setRequestProperty("Accept-Encoding", "gzip");
501+
if (!uc.getRequestMethod().equals(method))
502+
throw new IllegalStateException("Failed to set the request method to "+method);
484503
}
485504

486505
private <T> T parse(Class<T> type, T instance) throws IOException {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.