Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17145] Android: Add support to HTTPClient for PATCH requests

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2015-05-15T02:30:00.000+0000
Affected Version/sRelease 3.2.3
Fix Version/sRelease 4.1.0
ComponentsAndroid
LabelsHttpClient
ReporterNIck
AssigneeAshraf Abu
Created2014-05-22T22:24:28.000+0000
Updated2018-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.

Comments

  1. Ritu Agrawal 2014-06-12

    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
  2. Atticus White 2015-01-07

    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
  3. Ingo Muschenetz 2015-01-14

    [~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.
  4. Imobach Martín 2015-04-12

    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.
  5. Kiley Williams 2015-04-21

    @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
  6. Atticus White 2015-04-21

    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.
  7. Ashraf Abu 2015-05-15

    PR accepted. Document PR update: https://github.com/appcelerator/titanium_mobile/pull/6851
  8. Chee Kiat Ng 2015-05-15

    Document PR merged.
  9. Kiley Williams 2016-03-29

    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?
  10. Ashraf Abu 2016-03-29

    [~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.
  11. Atticus White 2016-03-29

    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-okhttp
  12. Kiley Williams 2016-03-29

    Atticus, 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 ;-))
  13. Kiley Williams 2016-03-29

    @Ashraf, also, do you have any links to where they mention future support?
  14. Ashraf Abu 2016-03-29

    Here's the Issue Tracker for Android: https://code.google.com/p/android/issues/detail?id=76611
  15. Christopher Williams 2016-07-20

    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
        var client = Ti.Network.createHTTPClient();
        // ... do whatever you typically do here.
        // Set the special header to have some servers treat this as PATCH
        client.setRequestHeader('X-HTTP-Method-Override', 'PATCH');
        // Prepare the connection. Note we actually do a POST
        client.open('POST', url);
        // Send the request.
        client.send(data);
        
  16. Kiley Williams 2016-07-20

    Thanks @cwilliams
  17. Eric Merriman 2018-08-06

    Cleaning up older fixed issues. If this issue should not have been closed as fixed, please reopen.

JSON Source