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 HTTP POST calls for any showcase PATCH RPCs #1261

Closed
Tracked by #1439
lqiu96 opened this issue Mar 3, 2023 · 1 comment · Fixed by #1262
Closed
Tracked by #1439

Allow HTTP POST calls for any showcase PATCH RPCs #1261

lqiu96 opened this issue Mar 3, 2023 · 1 comment · Fixed by #1262
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@lqiu96
Copy link
Contributor

lqiu96 commented Mar 3, 2023

I'm trying to add in the showcase compliance test suite for Java and I'm running into an issue with the PATCH calls.
Error:

Caused by: com.google.api.client.http.HttpResponseException: 400 Bad Request
POST http://localhost:7469/v1beta1/repeat:bodypatch
{"error":{"code":400,"message":"unrecognized request: POST \"/v1beta1/repeat:bodypatch\"","details":null,"Body":"","Header":null,"Errors":null}}
	at com.google.api.client.http.HttpResponseException$Builder.build(HttpResponseException.java:293)
	at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1118)
	at com.google.api.gax.httpjson.HttpRequestRunnable.run(HttpRequestRunnable.java:118)
	... 6 more

Java Gax-httpjson's module sends PATCH requests as a POST request with a x-http-method-override: PATCH header, which results in a 400 Bad Request. Looking at the historical reasons for this:
https://github.com/googleapis/gapic-generator-java/blob/c23f981e2ac3c573bed51e725dc7061551179400/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java#L217-L226

    // A workaround to support PATCH request. This assumes support of "X-HTTP-Method-Override"
    // header on the server side, which GCP services usually do.
    //
    // Long story short, the problems is as follows: gax-httpjson depends on NetHttpTransport class
    // from google-http-client, which depends on JDK standard java.net.HttpUrlConnection, which does
    // not support PATCH http method.
    //
    // It is a won't fix for JDK8: https://bugs.openjdk.java.net/browse/JDK-8207840.
    // A corresponding google-http-client issue:
    // https://github.com/googleapis/google-http-java-client/issues/167

I believe the mux router setup for bodyPatch to expect a PATCH request

router.HandleFunc("/v1beta1/repeat:bodypatch", rest.HandleRepeatDataBodyPatch).Methods("PATCH")

Possible fix (Thanks to Noah for pointing me here):

  • Adding a conditional for PATCH here:
    for _, handler := range registered {
    file.P(` router.HandleFunc(%q, rest.%s).Methods(%q)`, handler.pattern, handler.function, handler.verb)
    }

    so it would output
    router.HandleFunc("/v1beta1/repeat:bodypatch", rest.HandleRepeatDataBodyPatch).Methods("PATCH", "POST")

Alternatives:

  • Does Go Mux support x-http-method-override?
@lqiu96 lqiu96 added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Mar 3, 2023
@lqiu96 lqiu96 changed the title Allow the HTTP POST calls for any PATCH RPCs Allow HTTP POST calls for any showcase PATCH RPCs Mar 3, 2023
@noahdietz
Copy link
Collaborator

I don't think we need to worry about if gorilla/mux supports the specific header, we just need to extend the handler to/add a new handler that checks for the header on POST calls to that same path and sends it to the appropriate Go handler func (i.e. the update method)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants