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

AndroidClientHandler doesn't allow arbitrary HTTP methods #3544

Closed
eli-darkly opened this issue Aug 23, 2019 · 4 comments
Closed

AndroidClientHandler doesn't allow arbitrary HTTP methods #3544

eli-darkly opened this issue Aug 23, 2019 · 4 comments
Assignees
Labels
Area: App Runtime Issues in `libmonodroid.so`. enhancement Proposed change to current functionality.

Comments

@eli-darkly
Copy link

Steps to Reproduce

    var handler = new Xamarin.Android.Net.AndroidClientHandler();
    var client = new System.Net.Http.HttpClient(handler, true);
    var method = "REPORT";
    var uri = new System.Uri("example");
    var request = new System.Net.Http.HttpRequestMessage(message, uri);
    var response = await client.SendAsync(request);

Expected Behavior

Makes the request.

Actual Behavior

Throws:

Java.Net.ProtocolException : Expected one of [OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, PATCH] but was REPORT
 		 at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00092] in <760510b4e57841349034b874cfed862a>:0 
 		 at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00030] in <760510b4e57841349034b874cfed862a>:0 
 		 at Java.Net.HttpURLConnection.set_RequestMethod (System.String value) [0x0002b] in <2cac72f35744422ab26d61b53b0a2e29>:0 
 		 at Xamarin.Android.Net.AndroidClientHandler.SetupRequestInternal (System.Net.Http.HttpRequestMessage request, Java.Net.URLConnection conn) [0x0007e] in <2cac72f35744422ab26d61b53b0a2e29>:0 
 		 at Xamarin.Android.Net.AndroidClientHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x002fd] in <2cac72f35744422ab26d61b53b0a2e29>:0 

The underlying problem is in java.net.HttpURLConnection. This class has strong opinions on what is or isn't a valid HTTP method— that's a known issue, and the recommended workaround is simply to use a newer Java API. Therefore AndroidClientHandler isn't a fully compliant implementation of the .NET/Xamarin HTTP APIs, which don't have any such limitation on what HTTP methods you can use.

(It's true that REPORT isn't a standard HTTP method, but it's been spec'd and used for years, and general-purpose HTTP clients normally do not prohibit you from using any method you want; they just assume that if the server can't handle it, you'll get an error and that's your problem. And that is true of .NET and Xamarin... unless you use AndroidClientHandler.)

Version Information

=== Visual Studio Community 2019 for Mac ===

Version 8.2.4 (build 17)
Installation UUID: 2a7c02a1-941a-4806-b4e6-0b4549aa6ed2
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 5.14.0.85 (d16-2-fix-mac-updates / 86973979)

Package version: 600000327

=== Mono Framework MDK ===

Runtime:
Mono 6.0.0.327 (2019-02/f8ea05bddcb) (64-bit)
Package version: 600000327

=== NuGet ===

Version: 5.1.0.6013

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
2.1.12
2.1.11
2.1.9
2.1.2
2.1.1
2.0.5
1.1.4
1.0.7
SDK: /usr/local/share/dotnet/sdk/2.1.701/Sdks
SDK Versions:
2.1.701
2.1.700
2.1.505
2.1.302
2.1.301
2.1.4
1.1.4
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/6.0.0/lib/mono/msbuild/Current/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.11
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Apple Developer Tools ===

Xcode 10.2.1 (14490.122)
Build 10E1001

=== Xamarin.Mac ===

Version: 5.14.0.110 (Visual Studio Community)
Hash: a8bcecce
Branch: d16-2
Build date: 2019-06-28 07:31:43-0400

=== Xamarin.iOS ===

Version: 12.14.0.110 (Visual Studio Community)
Hash: a8bcecce
Branch: d16-2
Build date: 2019-06-28 07:31:42-0400

=== Xamarin.Android ===

Version: 9.4.0.51 (Visual Studio Community)
Commit: xamarin-android/d16-2/9fa7775
Android SDK: /Users/elibishop/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
7.0 (API level 24)
7.1 (API level 25)
8.0 (API level 26)
8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 29.0.1
SDK Build Tools Version: 28.0.3

Build Information:
Mono: mono/mono@e6f5369c2d2
Java.Interop: xamarin/java.interop/d16-2@d64ada5
LibZipSharp: grendello/LibZipSharp/d16-2@caa0c74
LibZip: nih-at/libzip@b95cf3f
ProGuard: xamarin/proguard@905836d
SQLite: xamarin/sqlite@8212a2d
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-2@6f6c969

=== Microsoft Mobile OpenJDK ===

Java SDK: /Users/elibishop/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android Device Manager ===

Version: 1.2.0.60
Hash: 686c817
Branch: remotes/origin/d16-2
Build date: 2019-08-07 15:49:58 UTC

=== Xamarin Designer ===

Version: 16.2.0.379
Hash: 3f0652957
Branch: remotes/origin/d16-2
Build date: 2019-08-01 17:32:50 UTC

=== Xamarin Inspector ===

Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 802040017
Git revision: 9b155edbf23e9fe8b477b3236a342164fabf5f6b
Build date: 2019-08-16 00:21:01+00
Build branch: release-8.2
Xamarin extensions: 9f2598b5f2371ba2903988c2cd87a9759d0255f2

=== Operating System ===

Mac OS X 10.14.5
Darwin 18.6.0 Darwin Kernel Version 18.6.0
Thu Apr 25 23:16:27 PDT 2019
root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64

Log File

n/a

@grendello
Copy link
Contributor

Hi @eli-darkly, I'm afraid this issue can't be fixed in Xamarin.Android at least at the moment. We pass the method through to the "native" backend and java.net.HttpURLConnection is the only implementation I'm aware of that's not deprecated (like okhttp) and available in standard Android between APIs 19 and 29 - the spectrum we must support. As a workaround, you might consider enabling BTLS and use the standard HttpClient (the reason Xamarin.Android client handler exists is that Mono doesn't support TLS 1.2+ without BTLS and we wanted a more "lightweight" option than that)

@grendello grendello added Area: App Runtime Issues in `libmonodroid.so`. feature-request labels Aug 27, 2019
@eli-darkly
Copy link
Author

@grendello Yeah, I was afraid of that. Unfortunately, we've had a great deal of trouble getting the standard HttpClient to be stable enough on Android - we were seeing lots of spurious timeouts and terrible performance until we switched to AndroidClientHandler. So at least for now, the only workaround we can really do is to avoid using unsupported HTTP methods.

@grendello
Copy link
Contributor

@eli-darkly I have a few ideas for (not so near, alas) future regarding HTTP clients, so there's still hope :)

@eli-darkly
Copy link
Author

@grendello Hi - do you know if there were any further developments on this in the last 2 years?

@ghost ghost locked as resolved and limited conversation to collaborators Jun 5, 2022
@jpobst jpobst added the enhancement Proposed change to current functionality. label Dec 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: App Runtime Issues in `libmonodroid.so`. enhancement Proposed change to current functionality.
Projects
None yet
Development

No branches or pull requests

4 participants