Allow to properly PATCH methods with JDK11+
vojkny opened this issue · comments
Feature Request
This is a followup issue for #274
Description
Currently PATCH methods are silently transformed to POST methods.
However, in java 11+ (https://stackoverflow.com/a/64048579/922584) you can use the HttpRequest class to do what you want:
val request = HttpRequest.newBuilder()
.uri(URI.create(uri))
.method("PATCH", HttpRequest.BodyPublishers.ofString(message))
.build()
Proposed Solution
It would be great if it was possible to leverage possibilities of JDK11+ and do correct PATCH
requests as some services ignore the x-http-method-override
header
Sounds! Good, maybe it is a time for us to move to Java11 instead.
I even tried to upgrade to HttpRequest myself, however the project does not build with current version of gradle/java and I couldn't even manage to run it :/
eg.:
Script compilation errors:
Line 10: if (requested.id.id == Android.libPlugin) {
^ Unresolved reference: Android
or
Line 11: Fuel.name,
^ Unresolved reference: Fuel
Line 12: Fuel.Android.name,
^ Unresolved reference: Fuel
Line 13: Fuel.Coroutines.name,
^ Unresolved reference: Fuel
Line 14: Fuel.Forge.name,
^ Unresolved reference: Fuel
Line 15: Fuel.Gson.name,
^ Unresolved reference: Fuel
Line 16: Fuel.Jackson.name,
^ Unresolved reference: Fuel
Line 17: Fuel.Json.name,
^ Unresolved reference: Fuel
For anyone who stumbles here – it can be hacked even without modifying current version of Fuel.
Two things need to be done:
- Enable
request.executionOptions.forceMethods = true
- To allow for reflectively forcing
PATCH
to the string value on JDK11+, one must add JVM command line arguments:--add-opens java.base/sun.net.www.protocol.https=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED