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

PATCH method transformed to POST method #274

Closed
alvico opened this issue Nov 20, 2017 · 2 comments
Closed

PATCH method transformed to POST method #274

alvico opened this issue Nov 20, 2017 · 2 comments

Comments

@alvico
Copy link

alvico commented Nov 20, 2017

Somehow a PATCH request method is received as POST request method in the server:

Client Request:
2017-11-20 16:35:39 INFO Main:66 - "Body : {"status": "rejected"}"
"Headers : (5)"
Accept-Encoding : compress;q=0.5, gzip;q=1.0
Content-Type : application/json
Authorization : Basic ....
X-API-Version : v1
Accept : /

Server logs:
2017-11-20T16:35:39.81+0100 [RTR/0] OUT abit.apps.emea.vwapps.io - [2017-11-20T15:35:39.757+0000] "POST /data/feedback/11111-1111-111-1111-1111111 HTTP/1.1" 400 22 296 "-" "Java/1.8.0_131" "IP:PORT" "IP:PORT" x_forwarded_for:"someIP, someIP" x_forwarded_proto:"https" vcap_request_id:"someID" response_time:0.06272777 app_id:"someID" app_index:"1"

I'm totally lost about why is this happening, tried same thing with a GoLang framework and it worked fine.

@alvico
Copy link
Author

alvico commented Nov 20, 2017

Found out the problem by reading the documentation ... xD

The default client is HttpClient which is a thin wrapper over java.net.HttpUrlConnnection. java.net.HttpUrlConnnection does not support a PATCH method. HttpClient converts PATCH requests to a POST request and adds a X-HTTP-Method-Override: PATCH header. While this is a semi-standard industry practice not all APIs are configured to accept this header by default.

@vojkny
Copy link

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