[TIMOB-17145] Android: Add support to HTTPClient for PATCH requests
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2015-05-15T02:30:00.000+0000 |
Affected Version/s | Release 3.2.3 |
Fix Version/s | Release 4.1.0 |
Components | Android |
Labels | HttpClient |
Reporter | NIck |
Assignee | Ashraf Abu |
Created | 2014-05-22T22:24:28.000+0000 |
Updated | 2018-08-06T17:49:19.000+0000 |
Description
It would be great if the HTTPClient supported PATCH requests. We use ASP Web Api 2 and the convention is to use a PATCH request for a partial update.
Moving this feature request to engineering for further evaluation and prioritization. Here is an informative link: https://www.mnot.net/blog/2012/09/05/patch
What's the roadmap looking like for introducing more request methods? It's impossible right now to integrate with any RESTful resources that requires PATCH with the current HTTP proxy utilizing apache's http client. And lookiing through the docs, it's apparent that the capability exists, the current approach just uses unsupporting factories. http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/methods/HttpPatch.html
[~atticoos] We don't have a direct ETA at the moment, but we are happy to review a PR if you are able to contribute one.
The problem seems to affect Android platform only. I tried to reproduce the problem in iOS with MobileSDK 3.5.0.GA, but it’s working as expected. [https://github.com/appcelerator/titanium_mobile/pull/6777] This PR’s been tested in Android with MobileSDK 4.1.0 (latest). But it should work for older SDKs. Attached to PR is an Alloy app index.js, a screenshot showing the problem and other screenshot with the expected outcome. Changes to http://docs.appcelerator.com/titanium/3.0/#!/guide/HTTPClient_and_the_Request_Lifecycle would also be needed.
@ingo, is there any update on this? I just hit this issue and it is a blocking bug, seeing as the API that I am using requires PATCH for an update to specific data
I'm still waiting on a solution as well @Yrkh8trnoy. https://github.com/appcelerator/titanium_mobile/pull/6777 seems to be a first step towards integrating the support for PATCH, but lacks support for the rest of the unsupported areas of the HTTP spec. In the meantime, if you have an immediate need, I've created an OkHttp client for Android https://github.com/ajwhite/titanium-okhttp. It can be installed with gittio nice and easily. Built with complete backward compatible integration with your existing http client, you basically just need to call a different factory method.
PR accepted. Document PR update: https://github.com/appcelerator/titanium_mobile/pull/6851
Document PR merged.
Looks like this popped back up for me folks: 03-28 17:04:22.477: E/TiHTTPClient(2944): (TiHttpClient-23) [32887,66809] HTTP Error (java.net.ProtocolException): Unknown method 'PATCH'; must be one of [OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE] 03-28 17:04:22.477: E/TiHTTPClient(2944): java.net.ProtocolException: Unknown method 'PATCH'; must be one of [OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE] 03-28 17:04:22.477: E/TiHTTPClient(2944): at java.net.HttpURLConnection.setRequestMethod(HttpURLConnection.java:685) 03-28 17:04:22.477: E/TiHTTPClient(2944): at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1137) 03-28 17:04:22.477: E/TiHTTPClient(2944): at java.lang.Thread.run(Thread.java:841) Any idea why it would resurface?
[~Yrkh8trnoy] PATCH is not supported. We have now moved to using HTTPUrlConnection which Android does not have PATCH available for now. They have mentioned it will be available in the future. This is due to the move away from APACHE HttpClient due to Android removing support for this. If you need PATCH, you could use the libraries/modules that will support PATCH.
Kiley, I ran into the same problem last year. I built a networking module that uses the OkHttp networking library, which supports
PATCH
. Perhaps this can help you out https://github.com/ajwhite/titanium-okhttpAtticus, yes sir, I remember and I saw and tried to revert back to using that a couple of hours ago. It looks like it's a bit outdated in terms of certain methods missing from the base HTTPClient you were extending. Any chance you can update that? I left you a message on GitHub. If so, it'd be a PERFECT fix right now. I'll try to locate you offline/PM. @Ashraf, thanks. Do you have any suggestions? (Besides Atticus' of course, which looks great if updated ;-))
@Ashraf, also, do you have any links to where they mention future support?
Here's the Issue Tracker for Android: https://code.google.com/p/android/issues/detail?id=76611
So the issue was introduced upstream in Android itself. Basically they moved from using Apache HTTPClient to wanting developers to use URLConnection. So we did. But Java/Android doesn't support PATCH on HttpURLConnection. So to truly support it we'd need to re-introduce the dependency back on Apache's HTTPClient in Titanium, and then only use that client if the request is a PATCH. That seems like a bit of overkill for this case, and would inflate app sizes. One possible workaround: Some servers have hacks in to workaround this deficiency in Java/Android of not having PATCH builtin You can try using a POST and setting a special header to see if the server will treat it as a PATCH: httpost.setHeader("X-HTTP-Method-Override", "PATCH"); Basically mimic this: http://stackoverflow.com/questions/25163131/httpurlconnection-invalid-http-method-patch
Thanks @cwilliams
Cleaning up older fixed issues. If this issue should not have been closed as fixed, please reopen.