Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to properly PATCH methods with JDK11+ #827

Open
vojkny opened this issue Jan 28, 2022 · 3 comments
Open

Allow to properly PATCH methods with JDK11+ #827

vojkny opened this issue Jan 28, 2022 · 3 comments

Comments

@vojkny
Copy link

vojkny commented Jan 28, 2022

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

@kittinunf
Copy link
Owner

Sounds! Good, maybe it is a time for us to move to Java11 instead.

@vojkny
Copy link
Author

vojkny commented May 31, 2022

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

@vojkny
Copy link
Author

vojkny commented May 31, 2022

For anyone who stumbles here – it can be hacked even without modifying current version of Fuel.

Two things need to be done:

  1. Enable request.executionOptions.forceMethods = true
  2. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants